| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='exercise basic bitmap functionality' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | . "$TEST_DIRECTORY"/lib-bitmap.sh |
| 7 | |
| 8 | # Likewise, allow individual tests to control whether or not they use |
| 9 | # the boundary-based traversal. |
| 10 | sane_unset GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL |
| 11 | |
| 12 | objpath () { |
| 13 | echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')" |
| 14 | } |
| 15 | |
| 16 | # show objects present in pack ($1 should be associated *.idx) |
| 17 | list_packed_objects () { |
| 18 | git show-index <"$1" >object-list && |
| 19 | cut -d' ' -f2 object-list |
| 20 | } |
| 21 | |
| 22 | # has_any pattern-file content-file |
| 23 | # tests whether content-file has any entry from pattern-file with entries being |
| 24 | # whole lines. |
| 25 | has_any () { |
| 26 | grep -Ff "$1" "$2" |
| 27 | } |
| 28 | |
| 29 | # Since name-hash values are stored in the .bitmap files, add a test |
| 30 | # that checks that the name-hash calculations are stable across versions. |
| 31 | # Not exhaustive, but these hashing algorithms would be hard to change |
| 32 | # without causing deviations here. |
| 33 | test_expect_success 'name-hash value stability' ' |
| 34 | cat >names <<-\EOF && |
| 35 | first |
| 36 | second |
| 37 | third |
| 38 | a/one-long-enough-for-collisions |
| 39 | b/two-long-enough-for-collisions |
| 40 | many/parts/to/this/path/enough/to/collide/in/v2 |
| 41 | enough/parts/to/this/path/enough/to/collide/in/v2 |
| 42 | EOF |
| 43 | |
| 44 | test-tool name-hash <names >out && |
| 45 | |
| 46 | cat >expect <<-\EOF && |
| 47 | 2582249472 1763573760 first |
| 48 | 2289942528 1188134912 second |
| 49 | 2300837888 1130758144 third |
| 50 | 2544516325 3963087891 a/one-long-enough-for-collisions |
| 51 | 2544516325 4013419539 b/two-long-enough-for-collisions |
| 52 | 1420111091 1709547268 many/parts/to/this/path/enough/to/collide/in/v2 |
| 53 | 1420111091 1709547268 enough/parts/to/this/path/enough/to/collide/in/v2 |
| 54 | EOF |
| 55 | |
| 56 | test_cmp expect out |
| 57 | ' |
| 58 | |
| 59 | test_bitmap_cases () { |
| 60 | writeLookupTable=false |
| 61 | for i in "$@" |
| 62 | do |
| 63 | case "$i" in |
| 64 | "pack.writeBitmapLookupTable") writeLookupTable=true;; |
| 65 | esac |
| 66 | done |
| 67 | |
| 68 | test_expect_success 'setup test repository' ' |
| 69 | rm -fr * .git && |
| 70 | git init && |
| 71 | git config pack.writeBitmapLookupTable '"$writeLookupTable"' |
| 72 | ' |
| 73 | setup_bitmap_history |
| 74 | |
| 75 | test_expect_success 'setup writing bitmaps during repack' ' |
| 76 | git config repack.writeBitmaps true |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'full repack creates bitmaps' ' |
| 80 | GIT_TRACE2_EVENT="$(pwd)/trace" \ |
| 81 | git repack -ad && |
| 82 | ls .git/objects/pack/ | grep bitmap >output && |
| 83 | test_line_count = 1 output && |
| 84 | test_grep "\"key\":\"num_selected_commits\",\"value\":\"106\"" trace && |
| 85 | test_grep "\"key\":\"num_maximal_commits\",\"value\":\"107\"" trace |
| 86 | ' |
| 87 | |
| 88 | basic_bitmap_tests |
| 89 | |
| 90 | test_expect_success 'pack-objects respects --local (non-local loose)' ' |
| 91 | git init --bare alt.git && |
| 92 | echo $(pwd)/alt.git/objects >.git/objects/info/alternates && |
| 93 | echo content1 >file1 && |
| 94 | # non-local loose object which is not present in bitmapped pack |
| 95 | altblob=$(GIT_DIR=alt.git git hash-object -w file1) && |
| 96 | # non-local loose object which is also present in bitmapped pack |
| 97 | git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin && |
| 98 | git add file1 && |
| 99 | test_tick && |
| 100 | git commit -m commit_file1 && |
| 101 | echo HEAD | git pack-objects --local --stdout --revs >1.pack && |
| 102 | git index-pack 1.pack && |
| 103 | list_packed_objects 1.idx >1.objects && |
| 104 | printf "%s\n" "$altblob" "$blob" >nonlocal-loose && |
| 105 | ! has_any nonlocal-loose 1.objects |
| 106 | ' |
| 107 | |
| 108 | test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' ' |
| 109 | echo content2 >file2 && |
| 110 | blob2=$(git hash-object -w file2) && |
| 111 | git add file2 && |
| 112 | test_tick && |
| 113 | git commit -m commit_file2 && |
| 114 | printf "%s\n" "$blob2" "$bitmaptip" >keepobjects && |
| 115 | pack2=$(git pack-objects pack2 <keepobjects) && |
| 116 | mv pack2-$pack2.* .git/objects/pack/ && |
| 117 | >.git/objects/pack/pack2-$pack2.keep && |
| 118 | rm $(objpath $blob2) && |
| 119 | echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack && |
| 120 | git index-pack 2a.pack && |
| 121 | list_packed_objects 2a.idx >2a.objects && |
| 122 | ! has_any keepobjects 2a.objects |
| 123 | ' |
| 124 | |
| 125 | test_expect_success 'pack-objects respects --local (non-local pack)' ' |
| 126 | mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ && |
| 127 | echo HEAD | git pack-objects --local --stdout --revs >2b.pack && |
| 128 | git index-pack 2b.pack && |
| 129 | list_packed_objects 2b.idx >2b.objects && |
| 130 | ! has_any keepobjects 2b.objects |
| 131 | ' |
| 132 | |
| 133 | test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' ' |
| 134 | ls .git/objects/pack/ | grep bitmap >output && |
| 135 | test_line_count = 1 output && |
| 136 | packbitmap=$(basename $(cat output) .bitmap) && |
| 137 | list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects && |
| 138 | test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" && |
| 139 | >.git/objects/pack/$packbitmap.keep && |
| 140 | echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack && |
| 141 | git index-pack 3a.pack && |
| 142 | list_packed_objects 3a.idx >3a.objects && |
| 143 | ! has_any packbitmap.objects 3a.objects |
| 144 | ' |
| 145 | |
| 146 | test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' ' |
| 147 | mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ && |
| 148 | rm -f .git/objects/pack/multi-pack-index && |
| 149 | test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" && |
| 150 | echo HEAD | git pack-objects --local --stdout --revs >3b.pack && |
| 151 | git index-pack 3b.pack && |
| 152 | list_packed_objects 3b.idx >3b.objects && |
| 153 | ! has_any packbitmap.objects 3b.objects |
| 154 | ' |
| 155 | |
| 156 | test_expect_success 'pack-objects to file can use bitmap' ' |
| 157 | # make sure we still have 1 bitmap index from previous tests |
| 158 | ls .git/objects/pack/ | grep bitmap >output && |
| 159 | test_line_count = 1 output && |
| 160 | # verify equivalent packs are generated with/without using bitmap index |
| 161 | # Be careful to not use the path-walk option in either case. |
| 162 | packasha1=$(git pack-objects --no-use-bitmap-index --no-path-walk --all packa </dev/null) && |
| 163 | packbsha1=$(git pack-objects --use-bitmap-index --no-path-walk --all packb </dev/null) && |
| 164 | list_packed_objects packa-$packasha1.idx >packa.objects && |
| 165 | list_packed_objects packb-$packbsha1.idx >packb.objects && |
| 166 | test_cmp packa.objects packb.objects |
| 167 | ' |
| 168 | |
| 169 | test_expect_success 'full repack, reusing previous bitmaps' ' |
| 170 | git repack -ad && |
| 171 | ls .git/objects/pack/ | grep bitmap >output && |
| 172 | test_line_count = 1 output |
| 173 | ' |
| 174 | |
| 175 | test_expect_success 'fetch (full bitmap)' ' |
| 176 | git --git-dir=clone.git fetch origin second:second && |
| 177 | git rev-parse HEAD >expect && |
| 178 | git --git-dir=clone.git rev-parse HEAD >actual && |
| 179 | test_cmp expect actual |
| 180 | ' |
| 181 | |
| 182 | test_expect_success 'create objects for missing-HAVE tests' ' |
| 183 | blob=$(echo "missing have" | git hash-object -w --stdin) && |
| 184 | tree=$(printf "100644 blob $blob\tfile\n" | git mktree) && |
| 185 | parent=$(echo parent | git commit-tree $tree) && |
| 186 | commit=$(echo commit | git commit-tree $tree -p $parent) && |
| 187 | cat >revs <<-EOF |
| 188 | HEAD |
| 189 | ^HEAD^ |
| 190 | ^$commit |
| 191 | EOF |
| 192 | ' |
| 193 | |
| 194 | test_expect_success 'pack-objects respects --incremental' ' |
| 195 | cat >revs2 <<-EOF && |
| 196 | HEAD |
| 197 | $commit |
| 198 | EOF |
| 199 | git pack-objects --incremental --stdout --revs <revs2 >4.pack && |
| 200 | git index-pack 4.pack && |
| 201 | list_packed_objects 4.idx >4.objects && |
| 202 | test_line_count = 4 4.objects && |
| 203 | git rev-list --objects $commit >revlist && |
| 204 | cut -d" " -f1 revlist |sort >objects && |
| 205 | test_cmp 4.objects objects |
| 206 | ' |
| 207 | |
| 208 | test_expect_success 'pack with missing blob' ' |
| 209 | rm $(objpath $blob) && |
| 210 | git pack-objects --stdout --revs <revs >/dev/null |
| 211 | ' |
| 212 | |
| 213 | test_expect_success 'pack with missing tree' ' |
| 214 | rm $(objpath $tree) && |
| 215 | git pack-objects --stdout --revs <revs >/dev/null |
| 216 | ' |
| 217 | |
| 218 | test_expect_success 'pack with missing parent' ' |
| 219 | rm $(objpath $parent) && |
| 220 | git pack-objects --stdout --revs <revs >/dev/null |
| 221 | ' |
| 222 | |
| 223 | test_expect_success JGIT,SHA1 'we can read jgit bitmaps' ' |
| 224 | git clone --bare . compat-jgit.git && |
| 225 | ( |
| 226 | cd compat-jgit.git && |
| 227 | rm -f objects/pack/*.bitmap && |
| 228 | jgit gc && |
| 229 | git rev-list --test-bitmap HEAD |
| 230 | ) |
| 231 | ' |
| 232 | |
| 233 | test_expect_success JGIT,SHA1 'jgit can read our bitmaps' ' |
| 234 | git clone --bare . compat-us.git && |
| 235 | ( |
| 236 | cd compat-us.git && |
| 237 | git config pack.writeBitmapLookupTable '"$writeLookupTable"' && |
| 238 | git repack -adb && |
| 239 | # jgit gc will barf if it does not like our bitmaps |
| 240 | jgit gc |
| 241 | ) |
| 242 | ' |
| 243 | |
| 244 | test_expect_success 'splitting packs does not generate bogus bitmaps' ' |
| 245 | test-tool genrandom foo 1m >rand && |
| 246 | git add rand && |
| 247 | git commit -m "commit with big file" && |
| 248 | git -c pack.packSizeLimit=500k repack -adb && |
| 249 | git init --bare no-bitmaps.git && |
| 250 | git -C no-bitmaps.git fetch .. HEAD |
| 251 | ' |
| 252 | |
| 253 | test_expect_success 'set up reusable pack' ' |
| 254 | rm -f .git/objects/pack/*.keep && |
| 255 | git repack -adb && |
| 256 | reusable_pack () { |
| 257 | git for-each-ref --format="%(objectname)" | |
| 258 | git pack-objects --delta-base-offset --revs --stdout "$@" |
| 259 | } |
| 260 | ' |
| 261 | |
| 262 | test_expect_success 'pack reuse respects --honor-pack-keep' ' |
| 263 | test_when_finished "rm -f .git/objects/pack/*.keep" && |
| 264 | for i in .git/objects/pack/*.pack |
| 265 | do |
| 266 | >${i%.pack}.keep || return 1 |
| 267 | done && |
| 268 | reusable_pack --honor-pack-keep >empty.pack && |
| 269 | git index-pack empty.pack && |
| 270 | git show-index <empty.idx >actual && |
| 271 | test_must_be_empty actual |
| 272 | ' |
| 273 | |
| 274 | test_expect_success 'pack reuse respects --local' ' |
| 275 | mv .git/objects/pack/* alt.git/objects/pack/ && |
| 276 | test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" && |
| 277 | reusable_pack --local >empty.pack && |
| 278 | git index-pack empty.pack && |
| 279 | git show-index <empty.idx >actual && |
| 280 | test_must_be_empty actual |
| 281 | ' |
| 282 | |
| 283 | test_expect_success 'pack reuse respects --incremental' ' |
| 284 | reusable_pack --incremental >empty.pack && |
| 285 | git index-pack empty.pack && |
| 286 | git show-index <empty.idx >actual && |
| 287 | test_must_be_empty actual |
| 288 | ' |
| 289 | |
| 290 | test_expect_success 'truncated bitmap fails gracefully (ewah)' ' |
| 291 | test_config pack.writebitmaphashcache false && |
| 292 | test_config pack.writebitmaplookuptable false && |
| 293 | git repack -ad && |
| 294 | git rev-list --use-bitmap-index --count --all >expect && |
| 295 | bitmap=$(ls .git/objects/pack/*.bitmap) && |
| 296 | test_when_finished "rm -f $bitmap" && |
| 297 | test_copy_bytes 256 <$bitmap >$bitmap.tmp && |
| 298 | mv -f $bitmap.tmp $bitmap && |
| 299 | git rev-list --use-bitmap-index --count --all >actual 2>stderr && |
| 300 | test_cmp expect actual && |
| 301 | test_grep corrupt.ewah.bitmap stderr |
| 302 | ' |
| 303 | |
| 304 | test_expect_success 'truncated bitmap fails gracefully (cache)' ' |
| 305 | git config pack.writeBitmapLookupTable '"$writeLookupTable"' && |
| 306 | git repack -ad && |
| 307 | git rev-list --use-bitmap-index --count --all >expect && |
| 308 | bitmap=$(ls .git/objects/pack/*.bitmap) && |
| 309 | test_when_finished "rm -f $bitmap" && |
| 310 | test_copy_bytes 512 <$bitmap >$bitmap.tmp && |
| 311 | mv -f $bitmap.tmp $bitmap && |
| 312 | git rev-list --use-bitmap-index --count --all >actual 2>stderr && |
| 313 | test_cmp expect actual && |
| 314 | test_grep corrupted.bitmap.index stderr |
| 315 | ' |
| 316 | |
| 317 | # Create a state of history with these properties: |
| 318 | # |
| 319 | # - refs that allow a client to fetch some new history, while sharing some old |
| 320 | # history with the server; we use branches delta-reuse-old and |
| 321 | # delta-reuse-new here |
| 322 | # |
| 323 | # - the new history contains an object that is stored on the server as a delta |
| 324 | # against a base that is in the old history |
| 325 | # |
| 326 | # - the base object is not immediately reachable from the tip of the old |
| 327 | # history; finding it would involve digging down through history we know the |
| 328 | # other side has |
| 329 | # |
| 330 | # This should result in a state where fetching from old->new would not |
| 331 | # traditionally reuse the on-disk delta (because we'd have to dig to realize |
| 332 | # that the client has it), but we will do so if bitmaps can tell us cheaply |
| 333 | # that the other side has it. |
| 334 | test_expect_success 'set up thin delta-reuse parent' ' |
| 335 | # This first commit contains the buried base object. |
| 336 | test-tool genrandom delta 16384 >file && |
| 337 | git add file && |
| 338 | git commit -m "delta base" && |
| 339 | base=$(git rev-parse --verify HEAD:file) && |
| 340 | |
| 341 | # These intermediate commits bury the base back in history. |
| 342 | # This becomes the "old" state. |
| 343 | for i in 1 2 3 4 5 |
| 344 | do |
| 345 | echo $i >file && |
| 346 | git commit -am "intermediate $i" || return 1 |
| 347 | done && |
| 348 | git branch delta-reuse-old && |
| 349 | |
| 350 | # And now our new history has a delta against the buried base. Note |
| 351 | # that this must be smaller than the original file, since pack-objects |
| 352 | # prefers to create deltas from smaller objects to larger. |
| 353 | test-tool genrandom delta 16300 >file && |
| 354 | git commit -am "delta result" && |
| 355 | delta=$(git rev-parse --verify HEAD:file) && |
| 356 | git branch delta-reuse-new && |
| 357 | |
| 358 | # Repack with bitmaps and double check that we have the expected delta |
| 359 | # relationship. |
| 360 | git repack -adb && |
| 361 | have_delta $delta $base |
| 362 | ' |
| 363 | |
| 364 | # Now we can sanity-check the non-bitmap behavior (that the server is not able |
| 365 | # to reuse the delta). This isn't strictly something we care about, so this |
| 366 | # test could be scrapped in the future. But it makes sure that the next test is |
| 367 | # actually triggering the feature we want. |
| 368 | # |
| 369 | # Note that our tools for working with on-the-wire "thin" packs are limited. So |
| 370 | # we actually perform the fetch, retain the resulting pack, and inspect the |
| 371 | # result. |
| 372 | test_expect_success 'fetch without bitmaps ignores delta against old base' ' |
| 373 | test_config pack.usebitmaps false && |
| 374 | test_when_finished "rm -rf client.git" && |
| 375 | git init --bare client.git && |
| 376 | ( |
| 377 | cd client.git && |
| 378 | git config transfer.unpackLimit 1 && |
| 379 | git fetch .. delta-reuse-old:delta-reuse-old && |
| 380 | git fetch .. delta-reuse-new:delta-reuse-new && |
| 381 | have_delta $delta $ZERO_OID |
| 382 | ) |
| 383 | ' |
| 384 | |
| 385 | # And do the same for the bitmap case, where we do expect to find the delta. |
| 386 | test_expect_success 'fetch with bitmaps can reuse old base' ' |
| 387 | test_config pack.usebitmaps true && |
| 388 | test_when_finished "rm -rf client.git" && |
| 389 | git init --bare client.git && |
| 390 | ( |
| 391 | cd client.git && |
| 392 | |
| 393 | # This test relies on reusing a delta, but if the |
| 394 | # path-walk machinery is engaged, the base object |
| 395 | # is considered too small to use during the |
| 396 | # dynamic computation, so is not used. |
| 397 | GIT_TEST_PACK_PATH_WALK=0 && |
| 398 | export GIT_TEST_PACK_PATH_WALK && |
| 399 | |
| 400 | git config transfer.unpackLimit 1 && |
| 401 | git fetch .. delta-reuse-old:delta-reuse-old && |
| 402 | git fetch .. delta-reuse-new:delta-reuse-new && |
| 403 | have_delta $delta $base |
| 404 | ) |
| 405 | ' |
| 406 | |
| 407 | test_expect_success 'pack.preferBitmapTips' ' |
| 408 | git init repo && |
| 409 | test_when_finished "rm -fr repo" && |
| 410 | ( |
| 411 | cd repo && |
| 412 | git config pack.writeBitmapLookupTable '"$writeLookupTable"' && |
| 413 | |
| 414 | # create enough commits that not all are receive bitmap |
| 415 | # coverage even if they are all at the tip of some reference. |
| 416 | test_commit_bulk --message="%s" 103 && |
| 417 | |
| 418 | git rev-list HEAD >commits.raw && |
| 419 | sort <commits.raw >commits && |
| 420 | |
| 421 | git log --format="create refs/tags/%s %H" HEAD >refs && |
| 422 | git update-ref --stdin <refs && |
| 423 | |
| 424 | git repack -adb && |
| 425 | test-tool bitmap list-commits | sort >bitmaps && |
| 426 | |
| 427 | # remember which commits did not receive bitmaps |
| 428 | comm -13 bitmaps commits >before && |
| 429 | test_file_not_empty before && |
| 430 | |
| 431 | # mark the commits which did not receive bitmaps as preferred, |
| 432 | # and generate the bitmap again |
| 433 | sed "s|\(.*\)|create refs/tags/include/\1 \1|" before | |
| 434 | git update-ref --stdin && |
| 435 | git -c pack.preferBitmapTips=refs/tags/include repack -adb && |
| 436 | |
| 437 | # finally, check that the commit(s) without bitmap coverage |
| 438 | # are not the same ones as before |
| 439 | test-tool bitmap list-commits | sort >bitmaps && |
| 440 | comm -13 bitmaps commits >after && |
| 441 | |
| 442 | ! test_cmp before after |
| 443 | ) |
| 444 | ' |
| 445 | |
| 446 | test_expect_success 'pack.preferBitmapTips' ' |
| 447 | git init repo && |
| 448 | test_when_finished "rm -rf repo" && |
| 449 | ( |
| 450 | cd repo && |
| 451 | git config pack.writeBitmapLookupTable '"$writeLookupTable"' && |
| 452 | test_commit_bulk --message="%s" 103 && |
| 453 | |
| 454 | cat >>.git/config <<-\EOF && |
| 455 | [pack] |
| 456 | preferBitmapTips |
| 457 | EOF |
| 458 | cat >expect <<-\EOF && |
| 459 | error: missing value for '\''pack.preferbitmaptips'\'' |
| 460 | EOF |
| 461 | |
| 462 | # Disable name hash version adjustment due to stderr comparison. |
| 463 | GIT_TEST_NAME_HASH_VERSION=1 \ |
| 464 | git repack -adb 2>actual && |
| 465 | test_cmp expect actual |
| 466 | ) |
| 467 | ' |
| 468 | |
| 469 | test_expect_success 'pack.preferBitmapTips interprets patterns as hierarchy' ' |
| 470 | git init repo && |
| 471 | test_when_finished "rm -fr repo" && |
| 472 | ( |
| 473 | cd repo && |
| 474 | |
| 475 | # Create enough commits that not all will receive bitmap |
| 476 | # coverage even if they are all at the tip of some reference. |
| 477 | test_commit_bulk --message="%s" 103 && |
| 478 | git log --format="create refs/tags/%s/tag %H" HEAD >refs && |
| 479 | git update-ref --stdin <refs && |
| 480 | |
| 481 | # Create the bitmap. |
| 482 | git repack -adb && |
| 483 | test-tool bitmap list-commits | sort >commits-with-bitmap && |
| 484 | |
| 485 | # Verify that we have at least one commit that did not |
| 486 | # receive a bitmap. |
| 487 | git rev-list HEAD >commits.raw && |
| 488 | sort <commits.raw >commits && |
| 489 | comm -13 commits-with-bitmap commits >commits-wo-bitmap && |
| 490 | test_file_not_empty commits-wo-bitmap && |
| 491 | commit_id=$(head commits-wo-bitmap) && |
| 492 | ref_without_bitmap=$(git for-each-ref --points-at="$commit_id" --format="%(refname)") && |
| 493 | |
| 494 | # When passing the full refname we do not expect a |
| 495 | # bitmap to be generated, as it should be interpreted |
| 496 | # as if a slash was appended to the pattern. |
| 497 | git -c pack.preferBitmapTips="$ref_without_bitmap" repack -adb && |
| 498 | test-tool bitmap list-commits >after && |
| 499 | test_grep ! "$commit_id" after && |
| 500 | |
| 501 | # But if we pass the parent directory of the ref we |
| 502 | # should see a bitmap. |
| 503 | ref_namespace=$(dirname "$ref_without_bitmap") && |
| 504 | git -c pack.preferBitmapTips="$ref_namespace" repack -adb && |
| 505 | test-tool bitmap list-commits >after && |
| 506 | test_grep "$commit_id" after |
| 507 | ) |
| 508 | ' |
| 509 | |
| 510 | test_expect_success 'complains about multiple pack bitmaps' ' |
| 511 | rm -fr repo && |
| 512 | git init repo && |
| 513 | test_when_finished "rm -fr repo" && |
| 514 | ( |
| 515 | cd repo && |
| 516 | git config pack.writeBitmapLookupTable '"$writeLookupTable"' && |
| 517 | |
| 518 | test_commit base && |
| 519 | |
| 520 | git repack -adb && |
| 521 | bitmap="$(ls .git/objects/pack/pack-*.bitmap)" && |
| 522 | mv "$bitmap" "$bitmap.bak" && |
| 523 | |
| 524 | test_commit other && |
| 525 | git repack -ab && |
| 526 | |
| 527 | mv "$bitmap.bak" "$bitmap" && |
| 528 | |
| 529 | find .git/objects/pack -type f -name "*.pack" >packs && |
| 530 | find .git/objects/pack -type f -name "*.bitmap" >bitmaps && |
| 531 | test_line_count = 2 packs && |
| 532 | test_line_count = 2 bitmaps && |
| 533 | |
| 534 | GIT_TRACE2_EVENT=$(pwd)/trace2.txt git rev-list --use-bitmap-index HEAD && |
| 535 | test_grep "opened bitmap" trace2.txt && |
| 536 | test_grep "ignoring extra bitmap" trace2.txt |
| 537 | ) |
| 538 | ' |
| 539 | |
| 540 | test_expect_success 'load corrupt bitmap' ' |
| 541 | rm -fr repo && |
| 542 | git init repo && |
| 543 | test_when_finished "rm -fr repo" && |
| 544 | ( |
| 545 | cd repo && |
| 546 | git config pack.writeBitmapLookupTable '"$writeLookupTable"' && |
| 547 | |
| 548 | test_commit base && |
| 549 | |
| 550 | git repack -adb && |
| 551 | bitmap="$(ls .git/objects/pack/pack-*.bitmap)" && |
| 552 | chmod +w $bitmap && |
| 553 | |
| 554 | test-tool bitmap list-commits-with-offset >offsets && |
| 555 | xor_off=$(head -n1 offsets | awk "{print \$3}") && |
| 556 | printf '\161' | |
| 557 | dd of=$bitmap count=1 bs=1 conv=notrunc seek=$xor_off && |
| 558 | |
| 559 | git rev-list --objects --no-object-names HEAD >expect.raw && |
| 560 | git rev-list --objects --use-bitmap-index --no-object-names HEAD \ |
| 561 | >actual.raw && |
| 562 | |
| 563 | sort expect.raw >expect && |
| 564 | sort actual.raw >actual && |
| 565 | |
| 566 | test_cmp expect actual |
| 567 | ) |
| 568 | ' |
| 569 | } |
| 570 | |
| 571 | test_bitmap_cases |
| 572 | |
| 573 | GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=1 |
| 574 | export GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL |
| 575 | |
| 576 | test_bitmap_cases |
| 577 | |
| 578 | sane_unset GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL |
| 579 | |
| 580 | test_expect_success 'path-walk repack can write and use bitmap indexes' ' |
| 581 | test_when_finished "rm -rf path-walk-bitmap" && |
| 582 | git init path-walk-bitmap && |
| 583 | ( |
| 584 | cd path-walk-bitmap && |
| 585 | test_commit first && |
| 586 | test_commit second && |
| 587 | test_commit third && |
| 588 | |
| 589 | git repack -a -d -b --path-walk && |
| 590 | git rev-list --test-bitmap --use-bitmap-index HEAD && |
| 591 | |
| 592 | git rev-parse HEAD >in && |
| 593 | |
| 594 | git rev-list --objects --no-object-names HEAD >expect.raw && |
| 595 | sort expect.raw >expect && |
| 596 | |
| 597 | for reuse in true false |
| 598 | do |
| 599 | : >trace.txt && |
| 600 | |
| 601 | GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ |
| 602 | git -c pack.allowPackReuse=$reuse pack-objects \ |
| 603 | --stdout --revs --path-walk --use-bitmap-index \ |
| 604 | <in >out.pack && |
| 605 | test_grep "\"category\":\"bitmap\",\"key\":\"bitmap/hits\"" trace.txt && |
| 606 | |
| 607 | git index-pack out.pack && |
| 608 | |
| 609 | list_packed_objects out.idx >actual.raw && |
| 610 | sort actual.raw >actual && |
| 611 | test_cmp expect actual || return 1 |
| 612 | done |
| 613 | ) |
| 614 | ' |
| 615 | |
| 616 | test_expect_success 'incremental repack fails when bitmaps are requested' ' |
| 617 | test_commit more-1 && |
| 618 | test_must_fail git repack -d 2>err && |
| 619 | test_grep "Incremental repacks are incompatible with bitmap" err |
| 620 | ' |
| 621 | |
| 622 | test_expect_success 'incremental repack can disable bitmaps' ' |
| 623 | test_commit more-2 && |
| 624 | git repack -d --no-write-bitmap-index |
| 625 | ' |
| 626 | |
| 627 | test_expect_success 'boundary-based traversal is used when requested' ' |
| 628 | git repack -a -d --write-bitmap-index && |
| 629 | |
| 630 | for argv in \ |
| 631 | "git -c pack.useBitmapBoundaryTraversal=true" \ |
| 632 | "git -c feature.experimental=true" \ |
| 633 | "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=1 git" |
| 634 | do |
| 635 | eval "GIT_TRACE2_EVENT=1 $argv rev-list --objects \ |
| 636 | --use-bitmap-index second..other 2>perf" && |
| 637 | test_grep "\"region_enter\".*\"label\":\"haves/boundary\"" perf || |
| 638 | return 1 |
| 639 | done && |
| 640 | |
| 641 | for argv in \ |
| 642 | "git -c pack.useBitmapBoundaryTraversal=false" \ |
| 643 | "git -c feature.experimental=true -c pack.useBitmapBoundaryTraversal=false" \ |
| 644 | "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=0 git -c pack.useBitmapBoundaryTraversal=true" \ |
| 645 | "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=0 git -c feature.experimental=true" |
| 646 | do |
| 647 | eval "GIT_TRACE2_EVENT=1 $argv rev-list --objects \ |
| 648 | --use-bitmap-index second..other 2>perf" && |
| 649 | test_grep "\"region_enter\".*\"label\":\"haves/classic\"" perf || |
| 650 | return 1 |
| 651 | done |
| 652 | ' |
| 653 | |
| 654 | test_expect_success 'left-right not confused by bitmap index' ' |
| 655 | git rev-list --left-right other...HEAD >expect && |
| 656 | git rev-list --use-bitmap-index --left-right other...HEAD >actual && |
| 657 | test_cmp expect actual |
| 658 | ' |
| 659 | |
| 660 | test_expect_success 'left-right count not confused by bitmap-index' ' |
| 661 | git rev-list --left-right --count other...HEAD >expect && |
| 662 | git rev-list --use-bitmap-index --left-right --count other...HEAD >actual && |
| 663 | test_cmp expect actual |
| 664 | ' |
| 665 | |
| 666 | test_bitmap_cases "pack.writeBitmapLookupTable" |
| 667 | |
| 668 | test_expect_success 'verify writing bitmap lookup table when enabled' ' |
| 669 | GIT_TRACE2_EVENT="$(pwd)/trace2" \ |
| 670 | git repack -ad && |
| 671 | test_grep "\"label\":\"writing_lookup_table\"" trace2 |
| 672 | ' |
| 673 | |
| 674 | test_expect_success 'truncated bitmap fails gracefully (lookup table)' ' |
| 675 | test_config pack.writebitmaphashcache false && |
| 676 | git repack -adb && |
| 677 | git rev-list --use-bitmap-index --count --all >expect && |
| 678 | bitmap=$(ls .git/objects/pack/*.bitmap) && |
| 679 | test_when_finished "rm -f $bitmap" && |
| 680 | test_copy_bytes 512 <$bitmap >$bitmap.tmp && |
| 681 | mv -f $bitmap.tmp $bitmap && |
| 682 | git rev-list --use-bitmap-index --count --all >actual 2>stderr && |
| 683 | test_cmp expect actual && |
| 684 | test_grep corrupted.bitmap.index stderr |
| 685 | ' |
| 686 | |
| 687 | test_expect_success 'test-tool bitmap write determines bitmap selection' ' |
| 688 | test_when_finished "rm -fr bitmap-write-helper" && |
| 689 | git init bitmap-write-helper && |
| 690 | ( |
| 691 | cd bitmap-write-helper && |
| 692 | |
| 693 | test_commit_bulk 64 && |
| 694 | git repack -ad && |
| 695 | |
| 696 | pack="$(ls .git/objects/pack/pack-*.pack)" && |
| 697 | |
| 698 | git rev-parse HEAD >in && |
| 699 | test-tool bitmap write "$(basename $pack)" <in && |
| 700 | |
| 701 | test-tool bitmap list-commits >bitmaps.raw && |
| 702 | sort bitmaps.raw >bitmaps && |
| 703 | test_cmp in bitmaps && |
| 704 | |
| 705 | git rev-list --count --objects --use-bitmap-index HEAD >actual && |
| 706 | git rev-list --count --objects HEAD >expect && |
| 707 | test_cmp expect actual |
| 708 | ) |
| 709 | ' |
| 710 | |
| 711 | test_done |