3 test_description
='exercise basic bitmap functionality'
7 echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')"
10 # show objects present in pack ($1 should be associated *.idx)
11 list_packed_objects
() {
12 git show-index
<"$1" >object-list
&&
13 cut
-d' ' -f2 object-list
16 # has_any pattern-file content-file
17 # tests whether content-file has any entry from pattern-file with entries being
23 test_expect_success
'setup repo with moderate-sized history' '
24 test_commit_bulk --id=file 100 &&
25 git checkout -b other HEAD~5 &&
26 test_commit_bulk --id=side 10 &&
27 git checkout master &&
28 bitmaptip=$(git rev-parse master) &&
29 blob=$(echo tagged-blob | git hash-object -w --stdin) &&
30 git tag tagged-blob $blob &&
31 git config repack.writebitmaps true
34 test_expect_success
'full repack creates bitmaps' '
36 ls .git/objects/pack/ | grep bitmap >output &&
37 test_line_count = 1 output
40 test_expect_success
'rev-list --test-bitmap verifies bitmaps' '
41 git rev-list --test-bitmap HEAD
47 test_expect_success
"counting commits via bitmap ($state)" '
48 git rev-list --count HEAD >expect &&
49 git rev-list --use-bitmap-index --count HEAD >actual &&
50 test_cmp expect actual
53 test_expect_success
"counting partial commits via bitmap ($state)" '
54 git rev-list --count HEAD~5..HEAD >expect &&
55 git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
56 test_cmp expect actual
59 test_expect_success
"counting commits with limit ($state)" '
60 git rev-list --count -n 1 HEAD >expect &&
61 git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
62 test_cmp expect actual
65 test_expect_success
"counting non-linear history ($state)" '
66 git rev-list --count other...master >expect &&
67 git rev-list --use-bitmap-index --count other...master >actual &&
68 test_cmp expect actual
71 test_expect_success
"counting commits with limiting ($state)" '
72 git rev-list --count HEAD -- 1.t >expect &&
73 git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
74 test_cmp expect actual
77 test_expect_success
"counting objects via bitmap ($state)" '
78 git rev-list --count --objects HEAD >expect &&
79 git rev-list --use-bitmap-index --count --objects HEAD >actual &&
80 test_cmp expect actual
83 test_expect_success
"enumerate commits ($state)" '
84 git rev-list --use-bitmap-index HEAD >actual &&
85 git rev-list HEAD >expect &&
86 test_bitmap_traversal --no-confirm-bitmaps expect actual
89 test_expect_success
"enumerate --objects ($state)" '
90 git rev-list --objects --use-bitmap-index HEAD >actual &&
91 git rev-list --objects HEAD >expect &&
92 test_bitmap_traversal expect actual
95 test_expect_success
"bitmap --objects handles non-commit objects ($state)" '
96 git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
101 rev_list_tests
'full bitmap'
103 test_expect_success
'clone from bitmapped repository' '
104 git clone --no-local --bare . clone.git &&
105 git rev-parse HEAD >expect &&
106 git --git-dir=clone.git rev-parse HEAD >actual &&
107 test_cmp expect actual
110 test_expect_success
'partial clone from bitmapped repository' '
111 test_config uploadpack.allowfilter true &&
112 git clone --no-local --bare --filter=blob:none . partial-clone.git &&
114 cd partial-clone.git &&
115 pack=$(echo objects/pack/*.pack) &&
116 git verify-pack -v "$pack" >have &&
117 awk "/blob/ { print \$1 }" <have >blobs &&
118 # we expect this single blob because of the direct ref
119 git rev-parse refs/tags/tagged-blob >expect &&
120 test_cmp expect blobs
124 test_expect_success
'setup further non-bitmapped commits' '
125 test_commit_bulk --id=further 10
128 rev_list_tests
'partial bitmap'
130 test_expect_success
'fetch (partial bitmap)' '
131 git --git-dir=clone.git fetch origin master:master &&
132 git rev-parse HEAD >expect &&
133 git --git-dir=clone.git rev-parse HEAD >actual &&
134 test_cmp expect actual
137 test_expect_success
'incremental repack fails when bitmaps are requested' '
138 test_commit more-1 &&
139 test_must_fail git repack -d 2>err &&
140 test_i18ngrep "Incremental repacks are incompatible with bitmap" err
143 test_expect_success
'incremental repack can disable bitmaps' '
144 test_commit more-2 &&
145 git repack -d --no-write-bitmap-index
148 test_expect_success
'pack-objects respects --local (non-local loose)' '
149 git init --bare alt.git &&
150 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
151 echo content1 >file1 &&
152 # non-local loose object which is not present in bitmapped pack
153 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
154 # non-local loose object which is also present in bitmapped pack
155 git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
158 git commit -m commit_file1 &&
159 echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
160 git index-pack 1.pack &&
161 list_packed_objects 1.idx >1.objects &&
162 printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
163 ! has_any nonlocal-loose 1.objects
166 test_expect_success
'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
167 echo content2 >file2 &&
168 blob2=$(git hash-object -w file2) &&
171 git commit -m commit_file2 &&
172 printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
173 pack2=$(git pack-objects pack2 <keepobjects) &&
174 mv pack2-$pack2.* .git/objects/pack/ &&
175 >.git/objects/pack/pack2-$pack2.keep &&
176 rm $(objpath $blob2) &&
177 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
178 git index-pack 2a.pack &&
179 list_packed_objects 2a.idx >2a.objects &&
180 ! has_any keepobjects 2a.objects
183 test_expect_success
'pack-objects respects --local (non-local pack)' '
184 mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
185 echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
186 git index-pack 2b.pack &&
187 list_packed_objects 2b.idx >2b.objects &&
188 ! has_any keepobjects 2b.objects
191 test_expect_success
'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
192 ls .git/objects/pack/ | grep bitmap >output &&
193 test_line_count = 1 output &&
194 packbitmap=$(basename $(cat output) .bitmap) &&
195 list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
196 test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
197 >.git/objects/pack/$packbitmap.keep &&
198 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
199 git index-pack 3a.pack &&
200 list_packed_objects 3a.idx >3a.objects &&
201 ! has_any packbitmap.objects 3a.objects
204 test_expect_success
'pack-objects respects --local (non-local bitmapped pack)' '
205 mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
206 rm -f .git/objects/pack/multi-pack-index &&
207 test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
208 echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
209 git index-pack 3b.pack &&
210 list_packed_objects 3b.idx >3b.objects &&
211 ! has_any packbitmap.objects 3b.objects
214 test_expect_success
'pack-objects to file can use bitmap' '
215 # make sure we still have 1 bitmap index from previous tests
216 ls .git/objects/pack/ | grep bitmap >output &&
217 test_line_count = 1 output &&
218 # verify equivalent packs are generated with/without using bitmap index
219 packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
220 packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
221 list_packed_objects packa-$packasha1.idx >packa.objects &&
222 list_packed_objects packb-$packbsha1.idx >packb.objects &&
223 test_cmp packa.objects packb.objects
226 test_expect_success
'full repack, reusing previous bitmaps' '
228 ls .git/objects/pack/ | grep bitmap >output &&
229 test_line_count = 1 output
232 test_expect_success
'fetch (full bitmap)' '
233 git --git-dir=clone.git fetch origin master:master &&
234 git rev-parse HEAD >expect &&
235 git --git-dir=clone.git rev-parse HEAD >actual &&
236 test_cmp expect actual
239 test_expect_success
'create objects for missing-HAVE tests' '
240 blob=$(echo "missing have" | git hash-object -w --stdin) &&
241 tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
242 parent=$(echo parent | git commit-tree $tree) &&
243 commit=$(echo commit | git commit-tree $tree -p $parent) &&
251 test_expect_success
'pack-objects respects --incremental' '
256 git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
257 git index-pack 4.pack &&
258 list_packed_objects 4.idx >4.objects &&
259 test_line_count = 4 4.objects &&
260 git rev-list --objects $commit >revlist &&
261 cut -d" " -f1 revlist |sort >objects &&
262 test_cmp 4.objects objects
265 test_expect_success
'pack with missing blob' '
266 rm $(objpath $blob) &&
267 git pack-objects --stdout --revs <revs >/dev/null
270 test_expect_success
'pack with missing tree' '
271 rm $(objpath $tree) &&
272 git pack-objects --stdout --revs <revs >/dev/null
275 test_expect_success
'pack with missing parent' '
276 rm $(objpath $parent) &&
277 git pack-objects --stdout --revs <revs >/dev/null
280 test_expect_success JGIT
'we can read jgit bitmaps' '
281 git clone --bare . compat-jgit.git &&
283 cd compat-jgit.git &&
284 rm -f objects/pack/*.bitmap &&
286 git rev-list --test-bitmap HEAD
290 test_expect_success JGIT
'jgit can read our bitmaps' '
291 git clone --bare . compat-us.git &&
295 # jgit gc will barf if it does not like our bitmaps
300 test_expect_success
'splitting packs does not generate bogus bitmaps' '
301 test-tool genrandom foo $((1024 * 1024)) >rand &&
303 git commit -m "commit with big file" &&
304 git -c pack.packSizeLimit=500k repack -adb &&
305 git init --bare no-bitmaps.git &&
306 git -C no-bitmaps.git fetch .. HEAD
309 test_expect_success
'set up reusable pack' '
310 rm -f .git/objects/pack/*.keep &&
313 git for-each-ref --format="%(objectname)" |
314 git pack-objects --delta-base-offset --revs --stdout "$@"
318 test_expect_success
'pack reuse respects --honor-pack-keep' '
319 test_when_finished "rm -f .git/objects/pack/*.keep" &&
320 for i in .git/objects/pack/*.pack
324 reusable_pack --honor-pack-keep >empty.pack &&
325 git index-pack empty.pack &&
326 git show-index <empty.idx >actual &&
327 test_must_be_empty actual
330 test_expect_success
'pack reuse respects --local' '
331 mv .git/objects/pack/* alt.git/objects/pack/ &&
332 test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" &&
333 reusable_pack --local >empty.pack &&
334 git index-pack empty.pack &&
335 git show-index <empty.idx >actual &&
336 test_must_be_empty actual
339 test_expect_success
'pack reuse respects --incremental' '
340 reusable_pack --incremental >empty.pack &&
341 git index-pack empty.pack &&
342 git show-index <empty.idx >actual &&
343 test_must_be_empty actual
346 test_expect_success
'truncated bitmap fails gracefully (ewah)' '
347 test_config pack.writebitmaphashcache false &&
349 git rev-list --use-bitmap-index --count --all >expect &&
350 bitmap=$(ls .git/objects/pack/*.bitmap) &&
351 test_when_finished "rm -f $bitmap" &&
352 test_copy_bytes 512 <$bitmap >$bitmap.tmp &&
353 mv -f $bitmap.tmp $bitmap &&
354 git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
355 test_cmp expect actual &&
356 test_i18ngrep corrupt.ewah.bitmap stderr
359 test_expect_success
'truncated bitmap fails gracefully (cache)' '
361 git rev-list --use-bitmap-index --count --all >expect &&
362 bitmap=$(ls .git/objects/pack/*.bitmap) &&
363 test_when_finished "rm -f $bitmap" &&
364 test_copy_bytes 512 <$bitmap >$bitmap.tmp &&
365 mv -f $bitmap.tmp $bitmap &&
366 git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
367 test_cmp expect actual &&
368 test_i18ngrep corrupted.bitmap.index stderr
371 # have_delta <obj> <expected_base>
373 # Note that because this relies on cat-file, it might find _any_ copy of an
374 # object in the repository. The caller is responsible for making sure
375 # there's only one (e.g., via "repack -ad", or having just fetched a copy).
378 echo $1 | git cat-file
--batch-check="%(deltabase)" >actual
&&
379 test_cmp expect actual
382 # Create a state of history with these properties:
384 # - refs that allow a client to fetch some new history, while sharing some old
385 # history with the server; we use branches delta-reuse-old and
386 # delta-reuse-new here
388 # - the new history contains an object that is stored on the server as a delta
389 # against a base that is in the old history
391 # - the base object is not immediately reachable from the tip of the old
392 # history; finding it would involve digging down through history we know the
395 # This should result in a state where fetching from old->new would not
396 # traditionally reuse the on-disk delta (because we'd have to dig to realize
397 # that the client has it), but we will do so if bitmaps can tell us cheaply
398 # that the other side has it.
399 test_expect_success
'set up thin delta-reuse parent' '
400 # This first commit contains the buried base object.
401 test-tool genrandom delta 16384 >file &&
403 git commit -m "delta base" &&
404 base=$(git rev-parse --verify HEAD:file) &&
406 # These intermediate commits bury the base back in history.
407 # This becomes the "old" state.
411 git commit -am "intermediate $i" || return 1
413 git branch delta-reuse-old &&
415 # And now our new history has a delta against the buried base. Note
416 # that this must be smaller than the original file, since pack-objects
417 # prefers to create deltas from smaller objects to larger.
418 test-tool genrandom delta 16300 >file &&
419 git commit -am "delta result" &&
420 delta=$(git rev-parse --verify HEAD:file) &&
421 git branch delta-reuse-new &&
423 # Repack with bitmaps and double check that we have the expected delta
426 have_delta $delta $base
429 # Now we can sanity-check the non-bitmap behavior (that the server is not able
430 # to reuse the delta). This isn't strictly something we care about, so this
431 # test could be scrapped in the future. But it makes sure that the next test is
432 # actually triggering the feature we want.
434 # Note that our tools for working with on-the-wire "thin" packs are limited. So
435 # we actually perform the fetch, retain the resulting pack, and inspect the
437 test_expect_success
'fetch without bitmaps ignores delta against old base' '
438 test_config pack.usebitmaps false &&
439 test_when_finished "rm -rf client.git" &&
440 git init --bare client.git &&
443 git config transfer.unpackLimit 1 &&
444 git fetch .. delta-reuse-old:delta-reuse-old &&
445 git fetch .. delta-reuse-new:delta-reuse-new &&
446 have_delta $delta $ZERO_OID
450 # And do the same for the bitmap case, where we do expect to find the delta.
451 test_expect_success
'fetch with bitmaps can reuse old base' '
452 test_config pack.usebitmaps true &&
453 test_when_finished "rm -rf client.git" &&
454 git init --bare client.git &&
457 git config transfer.unpackLimit 1 &&
458 git fetch .. delta-reuse-old:delta-reuse-old &&
459 git fetch .. delta-reuse-new:delta-reuse-new &&
460 have_delta $delta $base