t / t5310-pack-bitmaps.shon commit remote: add a macro for "refs/tags/*:refs/tags/*" (750d0da)
   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)
  24        do
  25                test_commit $i
  26        done &&
  27        git checkout -b other HEAD~5 &&
  28        for i in $(test_seq 1 10)
  29        do
  30                test_commit side-$i
  31        done &&
  32        git checkout master &&
  33        bitmaptip=$(git rev-parse master) &&
  34        blob=$(echo tagged-blob | git hash-object -w --stdin) &&
  35        git tag tagged-blob $blob &&
  36        git config repack.writebitmaps true &&
  37        git config pack.writebitmaphashcache true
  38'
  39
  40test_expect_success 'full repack creates bitmaps' '
  41        git repack -ad &&
  42        ls .git/objects/pack/ | grep bitmap >output &&
  43        test_line_count = 1 output
  44'
  45
  46test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
  47        git rev-list --test-bitmap HEAD
  48'
  49
  50rev_list_tests() {
  51        state=$1
  52
  53        test_expect_success "counting commits via bitmap ($state)" '
  54                git rev-list --count HEAD >expect &&
  55                git rev-list --use-bitmap-index --count HEAD >actual &&
  56                test_cmp expect actual
  57        '
  58
  59        test_expect_success "counting partial commits via bitmap ($state)" '
  60                git rev-list --count HEAD~5..HEAD >expect &&
  61                git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
  62                test_cmp expect actual
  63        '
  64
  65        test_expect_success "counting commits with limit ($state)" '
  66                git rev-list --count -n 1 HEAD >expect &&
  67                git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
  68                test_cmp expect actual
  69        '
  70
  71        test_expect_success "counting non-linear history ($state)" '
  72                git rev-list --count other...master >expect &&
  73                git rev-list --use-bitmap-index --count other...master >actual &&
  74                test_cmp expect actual
  75        '
  76
  77        test_expect_success "counting commits with limiting ($state)" '
  78                git rev-list --count HEAD -- 1.t >expect &&
  79                git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
  80                test_cmp expect actual
  81        '
  82
  83        test_expect_success "enumerate --objects ($state)" '
  84                git rev-list --objects --use-bitmap-index HEAD >tmp &&
  85                cut -d" " -f1 <tmp >tmp2 &&
  86                sort <tmp2 >actual &&
  87                git rev-list --objects HEAD >tmp &&
  88                cut -d" " -f1 <tmp >tmp2 &&
  89                sort <tmp2 >expect &&
  90                test_cmp expect actual
  91        '
  92
  93        test_expect_success "bitmap --objects handles non-commit objects ($state)" '
  94                git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
  95                grep $blob actual
  96        '
  97}
  98
  99rev_list_tests 'full bitmap'
 100
 101test_expect_success 'clone from bitmapped repository' '
 102        git clone --no-local --bare . clone.git &&
 103        git rev-parse HEAD >expect &&
 104        git --git-dir=clone.git rev-parse HEAD >actual &&
 105        test_cmp expect actual
 106'
 107
 108test_expect_success 'setup further non-bitmapped commits' '
 109        for i in $(test_seq 1 10)
 110        do
 111                test_commit further-$i
 112        done
 113'
 114
 115rev_list_tests 'partial bitmap'
 116
 117test_expect_success 'fetch (partial bitmap)' '
 118        git --git-dir=clone.git fetch origin master:master &&
 119        git rev-parse HEAD >expect &&
 120        git --git-dir=clone.git rev-parse HEAD >actual &&
 121        test_cmp expect actual
 122'
 123
 124test_expect_success 'incremental repack fails when bitmaps are requested' '
 125        test_commit more-1 &&
 126        test_must_fail git repack -d 2>err &&
 127        test_i18ngrep "Incremental repacks are incompatible with bitmap" err
 128'
 129
 130test_expect_success 'incremental repack can disable bitmaps' '
 131        test_commit more-2 &&
 132        git repack -d --no-write-bitmap-index
 133'
 134
 135test_expect_success 'pack-objects respects --local (non-local loose)' '
 136        git init --bare alt.git &&
 137        echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
 138        echo content1 >file1 &&
 139        # non-local loose object which is not present in bitmapped pack
 140        altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
 141        # non-local loose object which is also present in bitmapped pack
 142        git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
 143        git add file1 &&
 144        test_tick &&
 145        git commit -m commit_file1 &&
 146        echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
 147        git index-pack 1.pack &&
 148        list_packed_objects 1.idx >1.objects &&
 149        printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
 150        ! has_any nonlocal-loose 1.objects
 151'
 152
 153test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
 154        echo content2 >file2 &&
 155        blob2=$(git hash-object -w file2) &&
 156        git add file2 &&
 157        test_tick &&
 158        git commit -m commit_file2 &&
 159        printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
 160        pack2=$(git pack-objects pack2 <keepobjects) &&
 161        mv pack2-$pack2.* .git/objects/pack/ &&
 162        >.git/objects/pack/pack2-$pack2.keep &&
 163        rm $(objpath $blob2) &&
 164        echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
 165        git index-pack 2a.pack &&
 166        list_packed_objects 2a.idx >2a.objects &&
 167        ! has_any keepobjects 2a.objects
 168'
 169
 170test_expect_success 'pack-objects respects --local (non-local pack)' '
 171        mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
 172        echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
 173        git index-pack 2b.pack &&
 174        list_packed_objects 2b.idx >2b.objects &&
 175        ! has_any keepobjects 2b.objects
 176'
 177
 178test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
 179        ls .git/objects/pack/ | grep bitmap >output &&
 180        test_line_count = 1 output &&
 181        packbitmap=$(basename $(cat output) .bitmap) &&
 182        list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
 183        test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
 184        >.git/objects/pack/$packbitmap.keep &&
 185        echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
 186        git index-pack 3a.pack &&
 187        list_packed_objects 3a.idx >3a.objects &&
 188        ! has_any packbitmap.objects 3a.objects
 189'
 190
 191test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
 192        mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
 193        test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
 194        echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
 195        git index-pack 3b.pack &&
 196        list_packed_objects 3b.idx >3b.objects &&
 197        ! has_any packbitmap.objects 3b.objects
 198'
 199
 200test_expect_success 'pack-objects to file can use bitmap' '
 201        # make sure we still have 1 bitmap index from previous tests
 202        ls .git/objects/pack/ | grep bitmap >output &&
 203        test_line_count = 1 output &&
 204        # verify equivalent packs are generated with/without using bitmap index
 205        packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
 206        packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
 207        list_packed_objects <packa-$packasha1.idx >packa.objects &&
 208        list_packed_objects <packb-$packbsha1.idx >packb.objects &&
 209        test_cmp packa.objects packb.objects
 210'
 211
 212test_expect_success 'full repack, reusing previous bitmaps' '
 213        git repack -ad &&
 214        ls .git/objects/pack/ | grep bitmap >output &&
 215        test_line_count = 1 output
 216'
 217
 218test_expect_success 'fetch (full bitmap)' '
 219        git --git-dir=clone.git fetch origin master:master &&
 220        git rev-parse HEAD >expect &&
 221        git --git-dir=clone.git rev-parse HEAD >actual &&
 222        test_cmp expect actual
 223'
 224
 225test_expect_success 'create objects for missing-HAVE tests' '
 226        blob=$(echo "missing have" | git hash-object -w --stdin) &&
 227        tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
 228        parent=$(echo parent | git commit-tree $tree) &&
 229        commit=$(echo commit | git commit-tree $tree -p $parent) &&
 230        cat >revs <<-EOF
 231        HEAD
 232        ^HEAD^
 233        ^$commit
 234        EOF
 235'
 236
 237test_expect_success 'pack-objects respects --incremental' '
 238        cat >revs2 <<-EOF &&
 239        HEAD
 240        $commit
 241        EOF
 242        git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
 243        git index-pack 4.pack &&
 244        list_packed_objects 4.idx >4.objects &&
 245        test_line_count = 4 4.objects &&
 246        git rev-list --objects $commit >revlist &&
 247        cut -d" " -f1 revlist |sort >objects &&
 248        test_cmp 4.objects objects
 249'
 250
 251test_expect_success 'pack with missing blob' '
 252        rm $(objpath $blob) &&
 253        git pack-objects --stdout --revs <revs >/dev/null
 254'
 255
 256test_expect_success 'pack with missing tree' '
 257        rm $(objpath $tree) &&
 258        git pack-objects --stdout --revs <revs >/dev/null
 259'
 260
 261test_expect_success 'pack with missing parent' '
 262        rm $(objpath $parent) &&
 263        git pack-objects --stdout --revs <revs >/dev/null
 264'
 265
 266test_expect_success JGIT 'we can read jgit bitmaps' '
 267        git clone . compat-jgit &&
 268        (
 269                cd compat-jgit &&
 270                rm -f .git/objects/pack/*.bitmap &&
 271                jgit gc &&
 272                git rev-list --test-bitmap HEAD
 273        )
 274'
 275
 276test_expect_success JGIT 'jgit can read our bitmaps' '
 277        git clone . compat-us &&
 278        (
 279                cd compat-us &&
 280                git repack -adb &&
 281                # jgit gc will barf if it does not like our bitmaps
 282                jgit gc
 283        )
 284'
 285
 286test_expect_success 'splitting packs does not generate bogus bitmaps' '
 287        test-genrandom foo $((1024 * 1024)) >rand &&
 288        git add rand &&
 289        git commit -m "commit with big file" &&
 290        git -c pack.packSizeLimit=500k repack -adb &&
 291        git init --bare no-bitmaps.git &&
 292        git -C no-bitmaps.git fetch .. HEAD
 293'
 294
 295test_expect_success 'set up reusable pack' '
 296        rm -f .git/objects/pack/*.keep &&
 297        git repack -adb &&
 298        reusable_pack () {
 299                git for-each-ref --format="%(objectname)" |
 300                git pack-objects --delta-base-offset --revs --stdout "$@"
 301        }
 302'
 303
 304test_expect_success 'pack reuse respects --honor-pack-keep' '
 305        test_when_finished "rm -f .git/objects/pack/*.keep" &&
 306        for i in .git/objects/pack/*.pack
 307        do
 308                >${i%.pack}.keep
 309        done &&
 310        reusable_pack --honor-pack-keep >empty.pack &&
 311        git index-pack empty.pack &&
 312        >expect &&
 313        git show-index <empty.idx >actual &&
 314        test_cmp expect actual
 315'
 316
 317test_expect_success 'pack reuse respects --local' '
 318        mv .git/objects/pack/* alt.git/objects/pack/ &&
 319        test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" &&
 320        reusable_pack --local >empty.pack &&
 321        git index-pack empty.pack &&
 322        >expect &&
 323        git show-index <empty.idx >actual &&
 324        test_cmp expect actual
 325'
 326
 327test_expect_success 'pack reuse respects --incremental' '
 328        reusable_pack --incremental >empty.pack &&
 329        git index-pack empty.pack &&
 330        >expect &&
 331        git show-index <empty.idx >actual &&
 332        test_cmp expect actual
 333'
 334test_done