t / t5310-pack-bitmaps.shon commit Merge branch 'rs/cocci' (69e6544)
   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 'pack-objects to file can use bitmap' '
 200        # make sure we still have 1 bitmap index from previous tests
 201        ls .git/objects/pack/ | grep bitmap >output &&
 202        test_line_count = 1 output &&
 203        # verify equivalent packs are generated with/without using bitmap index
 204        packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
 205        packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
 206        list_packed_objects <packa-$packasha1.idx >packa.objects &&
 207        list_packed_objects <packb-$packbsha1.idx >packb.objects &&
 208        test_cmp packa.objects packb.objects
 209'
 210
 211test_expect_success 'full repack, reusing previous bitmaps' '
 212        git repack -ad &&
 213        ls .git/objects/pack/ | grep bitmap >output &&
 214        test_line_count = 1 output
 215'
 216
 217test_expect_success 'fetch (full bitmap)' '
 218        git --git-dir=clone.git fetch origin master:master &&
 219        git rev-parse HEAD >expect &&
 220        git --git-dir=clone.git rev-parse HEAD >actual &&
 221        test_cmp expect actual
 222'
 223
 224test_expect_success 'create objects for missing-HAVE tests' '
 225        blob=$(echo "missing have" | git hash-object -w --stdin) &&
 226        tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
 227        parent=$(echo parent | git commit-tree $tree) &&
 228        commit=$(echo commit | git commit-tree $tree -p $parent) &&
 229        cat >revs <<-EOF
 230        HEAD
 231        ^HEAD^
 232        ^$commit
 233        EOF
 234'
 235
 236test_expect_success 'pack-objects respects --incremental' '
 237        cat >revs2 <<-EOF &&
 238        HEAD
 239        $commit
 240        EOF
 241        git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
 242        git index-pack 4.pack &&
 243        list_packed_objects 4.idx >4.objects &&
 244        test_line_count = 4 4.objects &&
 245        git rev-list --objects $commit >revlist &&
 246        cut -d" " -f1 revlist |sort >objects &&
 247        test_cmp 4.objects objects
 248'
 249
 250test_expect_success 'pack with missing blob' '
 251        rm $(objpath $blob) &&
 252        git pack-objects --stdout --revs <revs >/dev/null
 253'
 254
 255test_expect_success 'pack with missing tree' '
 256        rm $(objpath $tree) &&
 257        git pack-objects --stdout --revs <revs >/dev/null
 258'
 259
 260test_expect_success 'pack with missing parent' '
 261        rm $(objpath $parent) &&
 262        git pack-objects --stdout --revs <revs >/dev/null
 263'
 264
 265test_expect_success JGIT 'we can read jgit bitmaps' '
 266        git clone . compat-jgit &&
 267        (
 268                cd compat-jgit &&
 269                rm -f .git/objects/pack/*.bitmap &&
 270                jgit gc &&
 271                git rev-list --test-bitmap HEAD
 272        )
 273'
 274
 275test_expect_success JGIT 'jgit can read our bitmaps' '
 276        git clone . compat-us &&
 277        (
 278                cd compat-us &&
 279                git repack -adb &&
 280                # jgit gc will barf if it does not like our bitmaps
 281                jgit gc
 282        )
 283'
 284
 285test_expect_success 'splitting packs does not generate bogus bitmaps' '
 286        test-genrandom foo $((1024 * 1024)) >rand &&
 287        git add rand &&
 288        git commit -m "commit with big file" &&
 289        git -c pack.packSizeLimit=500k repack -adb &&
 290        git init --bare no-bitmaps.git &&
 291        git -C no-bitmaps.git fetch .. HEAD
 292'
 293
 294test_done