3 test_description
='exercise basic multi-pack bitmap functionality'
5 .
"${TEST_DIRECTORY}/lib-bitmap.sh"
7 # We'll be writing our own midx and bitmaps, so avoid getting confused by the
9 GIT_TEST_MULTI_PACK_INDEX
=0
10 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP
=0
12 # This test exercise multi-pack bitmap functionality where the object order is
13 # stored and read from a special chunk within the MIDX, so use the default
15 sane_unset GIT_TEST_MIDX_WRITE_REV
16 sane_unset GIT_TEST_MIDX_READ_RIDX
18 bitmap_reuse_tests
() {
21 writeLookupTable
=false
26 "pack.writeBitmapLookupTable") writeLookupTable
=true
;;
30 test_expect_success
"setup pack reuse tests ($from -> $to)" '
35 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
36 test_commit_bulk 16 &&
39 git config core.multiPackIndex true &&
40 if test "MIDX" = "$from"
43 git multi-pack-index write --bitmap
50 test_expect_success
"build bitmap from existing ($from -> $to)" '
53 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
54 test_commit_bulk --id=further 16 &&
57 if test "MIDX" = "$to"
60 git multi-pack-index write --bitmap
67 test_expect_success
"verify resulting bitmaps ($from -> $to)" '
70 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
72 git rev-list --test-bitmap refs/tags/old-tip &&
73 git rev-list --test-bitmap refs/tags/new-tip
78 test_midx_bitmap_cases
() {
79 writeLookupTable
=false
80 writeBitmapLookupTable
=
85 "pack.writeBitmapLookupTable")
87 writeBitmapLookupTable
="$i"
92 test_expect_success
'setup test_repository' '
95 git config pack.writeBitmapLookupTable '"$writeLookupTable"'
100 bitmap_reuse_tests
'pack' 'MIDX' "$writeBitmapLookupTable"
101 bitmap_reuse_tests
'MIDX' 'pack' "$writeBitmapLookupTable"
102 bitmap_reuse_tests
'MIDX' 'MIDX' "$writeBitmapLookupTable"
104 test_expect_success
'missing object closure fails gracefully' '
107 test_when_finished "rm -fr repo" &&
110 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
113 test_commit packed &&
115 # Do not pass "--revs"; we want a pack without the "loose"
117 git pack-objects $objdir/pack/pack <<-EOF &&
118 $(git rev-parse packed)
121 test_must_fail git multi-pack-index write --bitmap 2>err &&
122 grep "doesn.t have full closure" err &&
123 test_path_is_missing $midx
127 midx_bitmap_partial_tests
129 test_expect_success
'removing a MIDX clears stale bitmaps' '
132 test_when_finished "rm -fr repo" &&
135 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
138 git multi-pack-index write --bitmap &&
140 # Write a MIDX and bitmap; remove the MIDX but leave the bitmap.
141 stale_bitmap=$midx-$(midx_checksum $objdir).bitmap &&
144 # Then write a new MIDX.
147 git multi-pack-index write --bitmap &&
149 test_path_is_file $midx &&
150 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
151 test_path_is_missing $stale_bitmap
155 test_expect_success
'pack.preferBitmapTips' '
157 test_when_finished "rm -fr repo" &&
160 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
162 test_commit_bulk --message="%s" 103 &&
164 git log --format="%H" >commits.raw &&
165 sort <commits.raw >commits &&
167 git log --format="create refs/tags/%s %H" HEAD >refs &&
168 git update-ref --stdin <refs &&
170 git multi-pack-index write --bitmap &&
171 test_path_is_file $midx &&
172 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
174 test-tool bitmap list-commits | sort >bitmaps &&
175 comm -13 bitmaps commits >before &&
176 test_line_count = 1 before &&
178 perl -ne "printf(\"create refs/tags/include/%d \", $.); print" \
179 <before | git update-ref --stdin &&
181 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
184 git -c pack.preferBitmapTips=refs/tags/include \
185 multi-pack-index write --bitmap &&
186 test-tool bitmap list-commits | sort >bitmaps &&
187 comm -13 bitmaps commits >after &&
189 ! test_cmp before after
193 test_expect_success
'writing a bitmap with --refs-snapshot' '
195 test_when_finished "rm -fr repo" &&
198 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
203 git rev-parse one >snapshot &&
207 # First, write a MIDX which see both refs/tags/one and
208 # refs/tags/two (causing both of those commits to receive
210 git multi-pack-index write --bitmap &&
212 test_path_is_file $midx &&
213 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
215 test-tool bitmap list-commits | sort >bitmaps &&
216 grep "$(git rev-parse one)" bitmaps &&
217 grep "$(git rev-parse two)" bitmaps &&
219 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
222 # Then again, but with a refs snapshot which only sees
224 git multi-pack-index write --bitmap --refs-snapshot=snapshot &&
226 test_path_is_file $midx &&
227 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
229 test-tool bitmap list-commits | sort >bitmaps &&
230 grep "$(git rev-parse one)" bitmaps &&
231 ! grep "$(git rev-parse two)" bitmaps
235 test_expect_success
'write a bitmap with --refs-snapshot (preferred tips)' '
237 test_when_finished "rm -fr repo" &&
240 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
242 test_commit_bulk --message="%s" 103 &&
244 git log --format="%H" >commits.raw &&
245 sort <commits.raw >commits &&
247 git log --format="create refs/tags/%s %H" HEAD >refs &&
248 git update-ref --stdin <refs &&
250 git multi-pack-index write --bitmap &&
251 test_path_is_file $midx &&
252 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
254 test-tool bitmap list-commits | sort >bitmaps &&
255 comm -13 bitmaps commits >before &&
256 test_line_count = 1 before &&
259 grep -vf before commits.raw &&
260 # mark missing commits as preferred
264 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
267 git multi-pack-index write --bitmap --refs-snapshot=snapshot &&
268 test-tool bitmap list-commits | sort >bitmaps &&
269 comm -13 bitmaps commits >after &&
271 ! test_cmp before after
275 test_expect_success
'hash-cache values are propagated from pack bitmaps' '
278 test_when_finished "rm -fr repo" &&
281 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
287 test-tool bitmap dump-hashes >pack.raw &&
288 test_file_not_empty pack.raw &&
289 sort pack.raw >pack.hashes &&
293 git multi-pack-index write --bitmap &&
295 test-tool bitmap dump-hashes >midx.raw &&
296 sort midx.raw >midx.hashes &&
298 # ensure that every namehash in the pack bitmap can be found in
299 # the midx bitmap (i.e., that there are no oid-namehash pairs
300 # unique to the pack bitmap).
301 comm -23 pack.hashes midx.hashes >dropped.hashes &&
302 test_must_be_empty dropped.hashes
306 test_expect_success
'no .bitmap is written without any objects' '
309 test_when_finished "rm -fr repo" &&
312 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
314 empty="$(git pack-objects $objdir/pack/pack </dev/null)" &&
319 git multi-pack-index write --bitmap --stdin-packs \
322 grep "bitmap without any objects" err &&
324 test_path_is_file $midx &&
325 test_path_is_missing $midx-$(midx_checksum $objdir).bitmap
329 test_expect_success
'graceful fallback when missing reverse index' '
332 test_when_finished "rm -fr repo" &&
335 git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
339 # write a pack and MIDX bitmap containing base
341 git multi-pack-index write --bitmap &&
343 GIT_TEST_MIDX_READ_RIDX=0 \
344 git rev-list --use-bitmap-index HEAD 2>err &&
345 ! grep "ignoring extra bitmap file" err
350 test_midx_bitmap_cases
352 test_midx_bitmap_cases
"pack.writeBitmapLookupTable"
354 test_expect_success
'multi-pack-index write writes lookup table if enabled' '
357 test_when_finished "rm -fr repo" &&
361 git config pack.writeBitmapLookupTable true &&
363 GIT_TRACE2_EVENT="$(pwd)/trace" \
364 git multi-pack-index write --bitmap &&
365 grep "\"label\":\"writing_lookup_table\"" trace
369 test_expect_success
'preferred pack change with existing MIDX bitmap' '
370 git init preferred-pack-with-existing &&
372 cd preferred-pack-with-existing &&
377 git rev-list --objects --no-object-names base >p1.objects &&
378 git rev-list --objects --no-object-names other >p2.objects &&
380 p1="$(git pack-objects "$objdir/pack/pack" \
381 --delta-base-offset <p1.objects)" &&
382 p2="$(git pack-objects "$objdir/pack/pack" \
383 --delta-base-offset <p2.objects)" &&
385 # Generate a MIDX containing the first two packs,
386 # marking p1 as preferred, and ensure that it can be
387 # successfully cloned.
388 git multi-pack-index write --bitmap \
389 --preferred-pack="pack-$p1.pack" &&
390 test_path_is_file $midx &&
391 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
392 git clone --no-local . clone1 &&
394 # Then generate a new pack which sorts ahead of any
395 # existing pack (by tweaking the pack prefix).
397 git pack-objects --all --unpacked $objdir/pack/pack0 &&
399 # Generate a new MIDX which changes the preferred pack
400 # to a pack contained in the existing MIDX.
401 git multi-pack-index write --bitmap \
402 --preferred-pack="pack-$p2.pack" &&
403 test_path_is_file $midx &&
404 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
406 # When the above circumstances are met, the preferred
407 # pack should change appropriately and clones should
409 git clone --no-local . clone2
413 test_expect_success
'tagged commits are selected for bitmapping' '
416 test_when_finished "rm -fr repo" &&
420 test_commit --annotate base &&
423 # Remove refs/heads/main which points at the commit directly,
424 # leaving only a reference to the annotated tag.
425 git branch -M main &&
427 git branch -d main &&
429 git multi-pack-index write --bitmap &&
431 git rev-parse HEAD >want &&
432 test-tool bitmap list-commits >actual &&
433 grep $(cat want) actual
437 test_expect_success
'do not follow replace objects for MIDX bitmap' '
440 test_when_finished "rm -fr repo" &&
446 git checkout --orphan=orphan A &&
447 test_commit orphan &&
449 git replace A HEAD &&
450 git repack -ad --write-midx --write-bitmap-index &&
452 # generating reachability bitmaps with replace refs
453 # enabled will result in broken clones
454 git clone --no-local --bare . clone.git
460 printf "bogus" |
dd of
="$1" bs
=1 seek
="12" conv
=notrunc
463 test_expect_success
'git fsck correctly identifies good and bad bitmaps' '
465 test_when_finished rm -rf valid &&
467 test_commit_bulk 20 &&
470 # Move pack-bitmap aside so it is not deleted
472 packbitmap=$(ls .git/objects/pack/pack-*.bitmap) &&
473 mv "$packbitmap" "$packbitmap.bak" &&
475 test_commit_bulk 10 &&
476 git repack -b --write-midx &&
477 midxbitmap=$(ls .git/objects/pack/multi-pack-index-*.bitmap) &&
479 # Copy MIDX bitmap to backup. Copy pack bitmap from backup.
480 cp "$midxbitmap" "$midxbitmap.bak" &&
481 cp "$packbitmap.bak" "$packbitmap" &&
483 # fsck works at first
485 test_must_be_empty err &&
487 corrupt_file "$packbitmap" &&
488 test_must_fail git fsck 2>err &&
489 grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err &&
491 cp "$packbitmap.bak" "$packbitmap" &&
492 corrupt_file "$midxbitmap" &&
493 test_must_fail git fsck 2>err &&
494 grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err &&
496 corrupt_file "$packbitmap" &&
497 test_must_fail git fsck 2>err &&
498 grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err &&
499 grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err
502 test_expect_success
'corrupt MIDX with bitmap causes fallback' '
503 git init corrupt-midx-bitmap &&
505 cd corrupt-midx-bitmap &&
509 test_commit second &&
512 git multi-pack-index write --bitmap &&
513 checksum=$(midx_checksum $objdir) &&
514 for f in $midx $midx-$checksum.bitmap
516 mv $f $f.bak || return 1
519 # pack everything together, invalidating the MIDX
521 # then restore the now-stale MIDX
522 for f in $midx $midx-$checksum.bitmap
524 mv $f.bak $f || return 1
527 git rev-list --count --objects --use-bitmap-index HEAD >out 2>err &&
528 # should attempt opening the broken pack twice (once
529 # from the attempt to load it via the stale bitmap, and
530 # again when attempting to load it from the stale MIDX)
531 # before falling back to the non-MIDX case
532 test 2 -eq $(grep -c "could not open pack" err) &&
533 test 6 -eq $(cat out)
537 for allow_pack_reuse
in single multi
539 test_expect_success
"reading MIDX without BTMP chunk does not complain with $allow_pack_reuse pack reuse" '
540 test_when_finished "rm -rf midx-without-btmp" &&
541 git init midx-without-btmp &&
543 cd midx-without-btmp &&
544 test_commit initial &&
546 git repack -Adbl --write-bitmap-index --write-midx &&
547 GIT_TEST_MIDX_READ_BTMP=false git -c pack.allowPackReuse=$allow_pack_reuse \
548 pack-objects --all --use-bitmap-index --stdout </dev/null >/dev/null 2>err &&
549 test_must_be_empty err