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
20 bitmap_reuse_tests
() {
24 test_expect_success
"setup pack reuse tests ($from -> $to)" '
29 test_commit_bulk 16 &&
32 git config core.multiPackIndex true &&
33 if test "MIDX" = "$from"
36 git multi-pack-index write --bitmap
43 test_expect_success
"build bitmap from existing ($from -> $to)" '
46 test_commit_bulk --id=further 16 &&
49 if test "MIDX" = "$to"
52 git multi-pack-index write --bitmap
59 test_expect_success
"verify resulting bitmaps ($from -> $to)" '
63 git rev-list --test-bitmap refs/tags/old-tip &&
64 git rev-list --test-bitmap refs/tags/new-tip
69 bitmap_reuse_tests
'pack' 'MIDX'
70 bitmap_reuse_tests
'MIDX' 'pack'
71 bitmap_reuse_tests
'MIDX' 'MIDX'
73 test_expect_success
'missing object closure fails gracefully' '
76 test_when_finished "rm -fr repo" &&
83 # Do not pass "--revs"; we want a pack without the "loose"
85 git pack-objects $objdir/pack/pack <<-EOF &&
86 $(git rev-parse packed)
89 test_must_fail git multi-pack-index write --bitmap 2>err &&
90 grep "doesn.t have full closure" err &&
91 test_path_is_missing $midx
95 midx_bitmap_partial_tests
97 test_expect_success
'removing a MIDX clears stale bitmaps' '
100 test_when_finished "rm -fr repo" &&
105 git multi-pack-index write --bitmap &&
107 # Write a MIDX and bitmap; remove the MIDX but leave the bitmap.
108 stale_bitmap=$midx-$(midx_checksum $objdir).bitmap &&
111 # Then write a new MIDX.
114 git multi-pack-index write --bitmap &&
116 test_path_is_file $midx &&
117 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
118 test_path_is_missing $stale_bitmap
122 test_expect_success
'pack.preferBitmapTips' '
124 test_when_finished "rm -fr repo" &&
128 test_commit_bulk --message="%s" 103 &&
130 git log --format="%H" >commits.raw &&
131 sort <commits.raw >commits &&
133 git log --format="create refs/tags/%s %H" HEAD >refs &&
134 git update-ref --stdin <refs &&
136 git multi-pack-index write --bitmap &&
137 test_path_is_file $midx &&
138 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
140 test-tool bitmap list-commits | sort >bitmaps &&
141 comm -13 bitmaps commits >before &&
142 test_line_count = 1 before &&
144 perl -ne "printf(\"create refs/tags/include/%d \", $.); print" \
145 <before | git update-ref --stdin &&
147 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
150 git -c pack.preferBitmapTips=refs/tags/include \
151 multi-pack-index write --bitmap &&
152 test-tool bitmap list-commits | sort >bitmaps &&
153 comm -13 bitmaps commits >after &&
155 ! test_cmp before after
159 test_expect_success
'writing a bitmap with --refs-snapshot' '
161 test_when_finished "rm -fr repo" &&
168 git rev-parse one >snapshot &&
172 # First, write a MIDX which see both refs/tags/one and
173 # refs/tags/two (causing both of those commits to receive
175 git multi-pack-index write --bitmap &&
177 test_path_is_file $midx &&
178 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
180 test-tool bitmap list-commits | sort >bitmaps &&
181 grep "$(git rev-parse one)" bitmaps &&
182 grep "$(git rev-parse two)" bitmaps &&
184 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
187 # Then again, but with a refs snapshot which only sees
189 git multi-pack-index write --bitmap --refs-snapshot=snapshot &&
191 test_path_is_file $midx &&
192 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
194 test-tool bitmap list-commits | sort >bitmaps &&
195 grep "$(git rev-parse one)" bitmaps &&
196 ! grep "$(git rev-parse two)" bitmaps
200 test_expect_success
'write a bitmap with --refs-snapshot (preferred tips)' '
202 test_when_finished "rm -fr repo" &&
206 test_commit_bulk --message="%s" 103 &&
208 git log --format="%H" >commits.raw &&
209 sort <commits.raw >commits &&
211 git log --format="create refs/tags/%s %H" HEAD >refs &&
212 git update-ref --stdin <refs &&
214 git multi-pack-index write --bitmap &&
215 test_path_is_file $midx &&
216 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
218 test-tool bitmap list-commits | sort >bitmaps &&
219 comm -13 bitmaps commits >before &&
220 test_line_count = 1 before &&
223 grep -vf before commits.raw &&
224 # mark missing commits as preferred
228 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
231 git multi-pack-index write --bitmap --refs-snapshot=snapshot &&
232 test-tool bitmap list-commits | sort >bitmaps &&
233 comm -13 bitmaps commits >after &&
235 ! test_cmp before after
239 test_expect_success
'hash-cache values are propagated from pack bitmaps' '
242 test_when_finished "rm -fr repo" &&
250 test-tool bitmap dump-hashes >pack.raw &&
251 test_file_not_empty pack.raw &&
252 sort pack.raw >pack.hashes &&
256 git multi-pack-index write --bitmap &&
258 test-tool bitmap dump-hashes >midx.raw &&
259 sort midx.raw >midx.hashes &&
261 # ensure that every namehash in the pack bitmap can be found in
262 # the midx bitmap (i.e., that there are no oid-namehash pairs
263 # unique to the pack bitmap).
264 comm -23 pack.hashes midx.hashes >dropped.hashes &&
265 test_must_be_empty dropped.hashes
269 test_expect_success
'no .bitmap is written without any objects' '
272 test_when_finished "rm -fr repo" &&
276 empty="$(git pack-objects $objdir/pack/pack </dev/null)" &&
281 git multi-pack-index write --bitmap --stdin-packs \
284 grep "bitmap without any objects" err &&
286 test_path_is_file $midx &&
287 test_path_is_missing $midx-$(midx_checksum $objdir).bitmap
291 test_expect_success
'graceful fallback when missing reverse index' '
294 test_when_finished "rm -fr repo" &&
300 # write a pack and MIDX bitmap containing base
302 git multi-pack-index write --bitmap &&
304 GIT_TEST_MIDX_READ_RIDX=0 \
305 git rev-list --use-bitmap-index HEAD 2>err &&
306 ! grep "ignoring extra bitmap file" err