a278d3032a772ef7ca3b3843e9a498c62000616c
   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
  10# show objects present in pack ($1 should be associated *.idx)
  11list_packed_objects () {
  12        git show-index <"$1" | cut -d' ' -f2
  13}
  14
  15# has_any pattern-file content-file
  16# tests whether content-file has any entry from pattern-file with entries being
  17# whole lines.
  18has_any () {
  19        grep -Ff "$1" "$2"
  20}
  21
  22test_expect_success 'setup repo with moderate-sized history' '
  23        for i in $(test_seq 1 10); do
  24                test_commit $i
  25        done &&
  26        git checkout -b other HEAD~5 &&
  27        for i in $(test_seq 1 10); do
  28                test_commit side-$i
  29        done &&
  30        git checkout master &&
  31        bitmaptip=$(git rev-parse master) &&
  32        blob=$(echo tagged-blob | git hash-object -w --stdin) &&
  33        git tag tagged-blob $blob &&
  34        git config repack.writebitmaps true &&
  35        git config pack.writebitmaphashcache true
  36'
  37
  38test_expect_success 'full repack creates bitmaps' '
  39        git repack -ad &&
  40        ls .git/objects/pack/ | grep bitmap >output &&
  41        test_line_count = 1 output
  42'
  43
  44test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
  45        git rev-list --test-bitmap HEAD
  46'
  47
  48rev_list_tests() {
  49        state=$1
  50
  51        test_expect_success "counting commits via bitmap ($state)" '
  52                git rev-list --count HEAD >expect &&
  53                git rev-list --use-bitmap-index --count HEAD >actual &&
  54                test_cmp expect actual
  55        '
  56
  57        test_expect_success "counting partial commits via bitmap ($state)" '
  58                git rev-list --count HEAD~5..HEAD >expect &&
  59                git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
  60                test_cmp expect actual
  61        '
  62
  63        test_expect_success "counting commits with limit ($state)" '
  64                git rev-list --count -n 1 HEAD >expect &&
  65                git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
  66                test_cmp expect actual
  67        '
  68
  69        test_expect_success "counting non-linear history ($state)" '
  70                git rev-list --count other...master >expect &&
  71                git rev-list --use-bitmap-index --count other...master >actual &&
  72                test_cmp expect actual
  73        '
  74
  75        test_expect_success "counting commits with limiting ($state)" '
  76                git rev-list --count HEAD -- 1.t >expect &&
  77                git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
  78                test_cmp expect actual
  79        '
  80
  81        test_expect_success "enumerate --objects ($state)" '
  82                git rev-list --objects --use-bitmap-index HEAD >tmp &&
  83                cut -d" " -f1 <tmp >tmp2 &&
  84                sort <tmp2 >actual &&
  85                git rev-list --objects HEAD >tmp &&
  86                cut -d" " -f1 <tmp >tmp2 &&
  87                sort <tmp2 >expect &&
  88                test_cmp expect actual
  89        '
  90
  91        test_expect_success "bitmap --objects handles non-commit objects ($state)" '
  92                git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
  93                grep $blob actual
  94        '
  95}
  96
  97rev_list_tests 'full bitmap'
  98
  99test_expect_success 'clone from bitmapped repository' '
 100        git clone --no-local --bare . clone.git &&
 101        git rev-parse HEAD >expect &&
 102        git --git-dir=clone.git rev-parse HEAD >actual &&
 103        test_cmp expect actual
 104'
 105
 106test_expect_success 'setup further non-bitmapped commits' '
 107        for i in $(test_seq 1 10); do
 108                test_commit further-$i
 109        done
 110'
 111
 112rev_list_tests 'partial bitmap'
 113
 114test_expect_success 'fetch (partial bitmap)' '
 115        git --git-dir=clone.git fetch origin master:master &&
 116        git rev-parse HEAD >expect &&
 117        git --git-dir=clone.git rev-parse HEAD >actual &&
 118        test_cmp expect actual
 119'
 120
 121test_expect_success 'incremental repack cannot create bitmaps' '
 122        test_commit more-1 &&
 123        find .git/objects/pack -name "*.bitmap" >expect &&
 124        git repack -d &&
 125        find .git/objects/pack -name "*.bitmap" >actual &&
 126        test_cmp expect actual
 127'
 128
 129test_expect_success 'incremental repack can disable bitmaps' '
 130        test_commit more-2 &&
 131        git repack -d --no-write-bitmap-index
 132'
 133
 134test_expect_success 'pack-objects respects --local (non-local loose)' '
 135        git init --bare alt.git &&
 136        echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
 137        echo content1 >file1 &&
 138        # non-local loose object which is not present in bitmapped pack
 139        altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
 140        # non-local loose object which is also present in bitmapped pack
 141        git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
 142        git add file1 &&
 143        test_tick &&
 144        git commit -m commit_file1 &&
 145        echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
 146        git index-pack 1.pack &&
 147        list_packed_objects 1.idx >1.objects &&
 148        printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
 149        ! has_any nonlocal-loose 1.objects
 150'
 151
 152test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
 153        echo content2 >file2 &&
 154        blob2=$(git hash-object -w file2) &&
 155        git add file2 &&
 156        test_tick &&
 157        git commit -m commit_file2 &&
 158        printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
 159        pack2=$(git pack-objects pack2 <keepobjects) &&
 160        mv pack2-$pack2.* .git/objects/pack/ &&
 161        >.git/objects/pack/pack2-$pack2.keep &&
 162        rm $(objpath $blob2) &&
 163        echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
 164        git index-pack 2a.pack &&
 165        list_packed_objects 2a.idx >2a.objects &&
 166        ! has_any keepobjects 2a.objects
 167'
 168
 169test_expect_success 'pack-objects respects --local (non-local pack)' '
 170        mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
 171        echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
 172        git index-pack 2b.pack &&
 173        list_packed_objects 2b.idx >2b.objects &&
 174        ! has_any keepobjects 2b.objects
 175'
 176
 177test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
 178        ls .git/objects/pack/ | grep bitmap >output &&
 179        test_line_count = 1 output &&
 180        packbitmap=$(basename $(cat output) .bitmap) &&
 181        list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
 182        test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
 183        >.git/objects/pack/$packbitmap.keep &&
 184        echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
 185        git index-pack 3a.pack &&
 186        list_packed_objects 3a.idx >3a.objects &&
 187        ! has_any packbitmap.objects 3a.objects
 188'
 189
 190test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
 191        mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
 192        test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
 193        echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
 194        git index-pack 3b.pack &&
 195        list_packed_objects 3b.idx >3b.objects &&
 196        ! has_any packbitmap.objects 3b.objects
 197'
 198
 199test_expect_success 'full repack, reusing previous bitmaps' '
 200        git repack -ad &&
 201        ls .git/objects/pack/ | grep bitmap >output &&
 202        test_line_count = 1 output
 203'
 204
 205test_expect_success 'fetch (full bitmap)' '
 206        git --git-dir=clone.git fetch origin master:master &&
 207        git rev-parse HEAD >expect &&
 208        git --git-dir=clone.git rev-parse HEAD >actual &&
 209        test_cmp expect actual
 210'
 211
 212test_expect_success 'create objects for missing-HAVE tests' '
 213        blob=$(echo "missing have" | git hash-object -w --stdin) &&
 214        tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
 215        parent=$(echo parent | git commit-tree $tree) &&
 216        commit=$(echo commit | git commit-tree $tree -p $parent) &&
 217        cat >revs <<-EOF
 218        HEAD
 219        ^HEAD^
 220        ^$commit
 221        EOF
 222'
 223
 224test_expect_success 'pack-objects respects --incremental' '
 225        cat >revs2 <<-EOF &&
 226        HEAD
 227        $commit
 228        EOF
 229        git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
 230        git index-pack 4.pack &&
 231        list_packed_objects 4.idx >4.objects &&
 232        test_line_count = 4 4.objects &&
 233        git rev-list --objects $commit >revlist &&
 234        cut -d" " -f1 revlist |sort >objects &&
 235        test_cmp 4.objects objects
 236'
 237
 238test_expect_success 'pack with missing blob' '
 239        rm $(objpath $blob) &&
 240        git pack-objects --stdout --revs <revs >/dev/null
 241'
 242
 243test_expect_success 'pack with missing tree' '
 244        rm $(objpath $tree) &&
 245        git pack-objects --stdout --revs <revs >/dev/null
 246'
 247
 248test_expect_success 'pack with missing parent' '
 249        rm $(objpath $parent) &&
 250        git pack-objects --stdout --revs <revs >/dev/null
 251'
 252
 253test_lazy_prereq JGIT '
 254        type jgit
 255'
 256
 257test_expect_success JGIT 'we can read jgit bitmaps' '
 258        git clone . compat-jgit &&
 259        (
 260                cd compat-jgit &&
 261                rm -f .git/objects/pack/*.bitmap &&
 262                jgit gc &&
 263                git rev-list --test-bitmap HEAD
 264        )
 265'
 266
 267test_expect_success JGIT 'jgit can read our bitmaps' '
 268        git clone . compat-us &&
 269        (
 270                cd compat-us &&
 271                git repack -adb &&
 272                # jgit gc will barf if it does not like our bitmaps
 273                jgit gc
 274        )
 275'
 276
 277test_expect_success 'splitting packs does not generate bogus bitmaps' '
 278        test-genrandom foo $((1024 * 1024)) >rand &&
 279        git add rand &&
 280        git commit -m "commit with big file" &&
 281        git -c pack.packSizeLimit=500k repack -adb &&
 282        git init --bare no-bitmaps.git &&
 283        git -C no-bitmaps.git fetch .. HEAD
 284'
 285
 286test_done