Merge branch 'gc/submodule-update-part2' into maint
[alt-git.git] / t / t5326-multi-pack-bitmaps.sh
blob4fe57414c13caca90d862b417ad5471cab28ee12
1 #!/bin/sh
3 test_description='exercise basic multi-pack bitmap functionality'
4 . ./test-lib.sh
5 . "${TEST_DIRECTORY}/lib-bitmap.sh"
7 # We'll be writing our own midx and bitmaps, so avoid getting confused by the
8 # automatic ones.
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
14 # behavior here.
15 sane_unset GIT_TEST_MIDX_WRITE_REV
16 sane_unset GIT_TEST_MIDX_READ_RIDX
18 midx_bitmap_core
20 bitmap_reuse_tests() {
21 from=$1
22 to=$2
24 test_expect_success "setup pack reuse tests ($from -> $to)" '
25 rm -fr repo &&
26 git init repo &&
28 cd repo &&
29 test_commit_bulk 16 &&
30 git tag old-tip &&
32 git config core.multiPackIndex true &&
33 if test "MIDX" = "$from"
34 then
35 git repack -Ad &&
36 git multi-pack-index write --bitmap
37 else
38 git repack -Adb
43 test_expect_success "build bitmap from existing ($from -> $to)" '
45 cd repo &&
46 test_commit_bulk --id=further 16 &&
47 git tag new-tip &&
49 if test "MIDX" = "$to"
50 then
51 git repack -d &&
52 git multi-pack-index write --bitmap
53 else
54 git repack -Adb
59 test_expect_success "verify resulting bitmaps ($from -> $to)" '
61 cd repo &&
62 git for-each-ref &&
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' '
74 rm -fr repo &&
75 git init repo &&
76 test_when_finished "rm -fr repo" &&
78 cd repo &&
80 test_commit loose &&
81 test_commit packed &&
83 # Do not pass "--revs"; we want a pack without the "loose"
84 # commit.
85 git pack-objects $objdir/pack/pack <<-EOF &&
86 $(git rev-parse packed)
87 EOF
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' '
98 rm -fr repo &&
99 git init repo &&
100 test_when_finished "rm -fr repo" &&
102 cd repo &&
103 test_commit base &&
104 git repack &&
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 &&
109 rm $midx &&
111 # Then write a new MIDX.
112 test_commit new &&
113 git repack &&
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' '
123 git init repo &&
124 test_when_finished "rm -fr repo" &&
126 cd 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 &&
148 rm -fr $midx &&
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' '
160 git init repo &&
161 test_when_finished "rm -fr repo" &&
163 cd repo &&
165 test_commit one &&
166 test_commit two &&
168 git rev-parse one >snapshot &&
170 git repack -ad &&
172 # First, write a MIDX which see both refs/tags/one and
173 # refs/tags/two (causing both of those commits to receive
174 # bitmaps).
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 &&
185 rm -fr $midx &&
187 # Then again, but with a refs snapshot which only sees
188 # refs/tags/one.
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)' '
201 git init repo &&
202 test_when_finished "rm -fr repo" &&
204 cd 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
225 sed "s/^/+/" before
226 ) >snapshot &&
228 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
229 rm -fr $midx &&
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' '
240 rm -fr repo &&
241 git init repo &&
242 test_when_finished "rm -fr repo" &&
244 cd repo &&
246 test_commit base &&
247 test_commit base2 &&
248 git repack -adb &&
250 test-tool bitmap dump-hashes >pack.raw &&
251 test_file_not_empty pack.raw &&
252 sort pack.raw >pack.hashes &&
254 test_commit new &&
255 git repack &&
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' '
270 rm -fr repo &&
271 git init repo &&
272 test_when_finished "rm -fr repo" &&
274 cd repo &&
276 empty="$(git pack-objects $objdir/pack/pack </dev/null)" &&
277 cat >packs <<-EOF &&
278 pack-$empty.idx
281 git multi-pack-index write --bitmap --stdin-packs \
282 <packs 2>err &&
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' '
292 rm -fr repo &&
293 git init repo &&
294 test_when_finished "rm -fr repo" &&
296 cd repo &&
298 test_commit base &&
300 # write a pack and MIDX bitmap containing base
301 git repack -adb &&
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
310 test_done