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