t / t5310-pack-bitmaps.shon commit Merge branch 'pt/pull-builtin' (5f02274)
   1#!/bin/sh
   2
   3test_description='exercise basic bitmap functionality'
   4. ./test-lib.sh
   5
   6objpath () {
   7        echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')"
   8}
   9
  10test_expect_success 'setup repo with moderate-sized history' '
  11        for i in $(test_seq 1 10); do
  12                test_commit $i
  13        done &&
  14        git checkout -b other HEAD~5 &&
  15        for i in $(test_seq 1 10); do
  16                test_commit side-$i
  17        done &&
  18        git checkout master &&
  19        blob=$(echo tagged-blob | git hash-object -w --stdin) &&
  20        git tag tagged-blob $blob &&
  21        git config repack.writebitmaps true &&
  22        git config pack.writebitmaphashcache true
  23'
  24
  25test_expect_success 'full repack creates bitmaps' '
  26        git repack -ad &&
  27        ls .git/objects/pack/ | grep bitmap >output &&
  28        test_line_count = 1 output
  29'
  30
  31test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
  32        git rev-list --test-bitmap HEAD
  33'
  34
  35rev_list_tests() {
  36        state=$1
  37
  38        test_expect_success "counting commits via bitmap ($state)" '
  39                git rev-list --count HEAD >expect &&
  40                git rev-list --use-bitmap-index --count HEAD >actual &&
  41                test_cmp expect actual
  42        '
  43
  44        test_expect_success "counting partial commits via bitmap ($state)" '
  45                git rev-list --count HEAD~5..HEAD >expect &&
  46                git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
  47                test_cmp expect actual
  48        '
  49
  50        test_expect_success "counting non-linear history ($state)" '
  51                git rev-list --count other...master >expect &&
  52                git rev-list --use-bitmap-index --count other...master >actual &&
  53                test_cmp expect actual
  54        '
  55
  56        test_expect_success "counting commits with limiting ($state)" '
  57                git rev-list --count HEAD -- 1.t >expect &&
  58                git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
  59                test_cmp expect actual
  60        '
  61
  62        test_expect_success "enumerate --objects ($state)" '
  63                git rev-list --objects --use-bitmap-index HEAD >tmp &&
  64                cut -d" " -f1 <tmp >tmp2 &&
  65                sort <tmp2 >actual &&
  66                git rev-list --objects HEAD >tmp &&
  67                cut -d" " -f1 <tmp >tmp2 &&
  68                sort <tmp2 >expect &&
  69                test_cmp expect actual
  70        '
  71
  72        test_expect_success "bitmap --objects handles non-commit objects ($state)" '
  73                git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
  74                grep $blob actual
  75        '
  76}
  77
  78rev_list_tests 'full bitmap'
  79
  80test_expect_success 'clone from bitmapped repository' '
  81        git clone --no-local --bare . clone.git &&
  82        git rev-parse HEAD >expect &&
  83        git --git-dir=clone.git rev-parse HEAD >actual &&
  84        test_cmp expect actual
  85'
  86
  87test_expect_success 'setup further non-bitmapped commits' '
  88        for i in $(test_seq 1 10); do
  89                test_commit further-$i
  90        done
  91'
  92
  93rev_list_tests 'partial bitmap'
  94
  95test_expect_success 'fetch (partial bitmap)' '
  96        git --git-dir=clone.git fetch origin master:master &&
  97        git rev-parse HEAD >expect &&
  98        git --git-dir=clone.git rev-parse HEAD >actual &&
  99        test_cmp expect actual
 100'
 101
 102test_expect_success 'incremental repack cannot create bitmaps' '
 103        test_commit more-1 &&
 104        find .git/objects/pack -name "*.bitmap" >expect &&
 105        git repack -d &&
 106        find .git/objects/pack -name "*.bitmap" >actual &&
 107        test_cmp expect actual
 108'
 109
 110test_expect_success 'incremental repack can disable bitmaps' '
 111        test_commit more-2 &&
 112        git repack -d --no-write-bitmap-index
 113'
 114
 115test_expect_success 'full repack, reusing previous bitmaps' '
 116        git repack -ad &&
 117        ls .git/objects/pack/ | grep bitmap >output &&
 118        test_line_count = 1 output
 119'
 120
 121test_expect_success 'fetch (full bitmap)' '
 122        git --git-dir=clone.git fetch origin master:master &&
 123        git rev-parse HEAD >expect &&
 124        git --git-dir=clone.git rev-parse HEAD >actual &&
 125        test_cmp expect actual
 126'
 127
 128test_expect_success 'create objects for missing-HAVE tests' '
 129        blob=$(echo "missing have" | git hash-object -w --stdin) &&
 130        tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
 131        parent=$(echo parent | git commit-tree $tree) &&
 132        commit=$(echo commit | git commit-tree $tree -p $parent) &&
 133        cat >revs <<-EOF
 134        HEAD
 135        ^HEAD^
 136        ^$commit
 137        EOF
 138'
 139
 140test_expect_success 'pack with missing blob' '
 141        rm $(objpath $blob) &&
 142        git pack-objects --stdout --revs <revs >/dev/null
 143'
 144
 145test_expect_success 'pack with missing tree' '
 146        rm $(objpath $tree) &&
 147        git pack-objects --stdout --revs <revs >/dev/null
 148'
 149
 150test_expect_success 'pack with missing parent' '
 151        rm $(objpath $parent) &&
 152        git pack-objects --stdout --revs <revs >/dev/null
 153'
 154
 155test_lazy_prereq JGIT '
 156        type jgit
 157'
 158
 159test_expect_success JGIT 'we can read jgit bitmaps' '
 160        git clone . compat-jgit &&
 161        (
 162                cd compat-jgit &&
 163                rm -f .git/objects/pack/*.bitmap &&
 164                jgit gc &&
 165                git rev-list --test-bitmap HEAD
 166        )
 167'
 168
 169test_expect_success JGIT 'jgit can read our bitmaps' '
 170        git clone . compat-us &&
 171        (
 172                cd compat-us &&
 173                git repack -adb &&
 174                # jgit gc will barf if it does not like our bitmaps
 175                jgit gc
 176        )
 177'
 178
 179test_expect_success 'splitting packs does not generate bogus bitmaps' '
 180        test-genrandom foo $((1024 * 1024)) >rand &&
 181        git add rand &&
 182        git commit -m "commit with big file" &&
 183        git -c pack.packSizeLimit=500k repack -adb &&
 184        git init --bare no-bitmaps.git &&
 185        git -C no-bitmaps.git fetch .. HEAD
 186'
 187
 188test_done