]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5310-pack-bitmaps.sh
Merge branch 'en/ort-perf-batch-9'
[thirdparty/git.git] / t / t5310-pack-bitmaps.sh
CommitLineData
212f2ffb
JK
1#!/bin/sh
2
3test_description='exercise basic bitmap functionality'
334afbc7
JS
4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
212f2ffb 7. ./test-lib.sh
ddfe9006
ÆAB
8. "$TEST_DIRECTORY"/lib-bundle.sh
9. "$TEST_DIRECTORY"/lib-bitmap.sh
212f2ffb 10
2db1a43f
VM
11objpath () {
12 echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')"
13}
14
702d1b95
KS
15# show objects present in pack ($1 should be associated *.idx)
16list_packed_objects () {
10c60017
SG
17 git show-index <"$1" >object-list &&
18 cut -d' ' -f2 object-list
702d1b95
KS
19}
20
21# has_any pattern-file content-file
22# tests whether content-file has any entry from pattern-file with entries being
23# whole lines.
24has_any () {
25 grep -Ff "$1" "$2"
26}
27
089f7513
DS
28# To ensure the logic for "maximal commits" is exercised, make
29# the repository a bit more complicated.
30#
45f4eeb2 31# other second
089f7513
DS
32# * *
33# (99 commits) (99 commits)
34# * *
35# |\ /|
45f4eeb2 36# | * octo-other octo-second * |
089f7513
DS
37# |/|\_________ ____________/|\|
38# | \ \/ __________/ |
39# | | ________/\ / |
40# * |/ * merge-right *
41# | _|__________/ \____________ |
42# |/ | \|
43# (l1) * * merge-left * (r1)
44# | / \________________________ |
45# |/ \|
46# (l2) * * (r2)
47# \___________________________ |
48# \|
49# * (base)
50#
45f4eeb2
DS
51# We only push bits down the first-parent history, which
52# makes some of these commits unimportant!
53#
089f7513
DS
54# The important part for the maximal commit algorithm is how
55# the bitmasks are extended. Assuming starting bit positions
45f4eeb2
DS
56# for second (bit 0) and other (bit 1), the bitmasks at the
57# end should be:
089f7513 58#
45f4eeb2 59# second: 1 (maximal, selected)
089f7513 60# other: 01 (maximal, selected)
45f4eeb2
DS
61# (base): 11 (maximal)
62#
63# This complicated history was important for a previous
64# version of the walk that guarantees never walking a
65# commit multiple times. That goal might be important
66# again, so preserve this complicated case. For now, this
67# test will guarantee that the bitmaps are computed
68# correctly, even with the repeat calculations.
089f7513 69
212f2ffb 70test_expect_success 'setup repo with moderate-sized history' '
089f7513 71 test_commit_bulk --id=file 10 &&
c5cd7490 72 git branch -M second &&
212f2ffb 73 git checkout -b other HEAD~5 &&
b1c36cb8 74 test_commit_bulk --id=side 10 &&
089f7513
DS
75
76 # add complicated history setup, including merges and
77 # ambiguous merge-bases
78
79 git checkout -b merge-left other~2 &&
80 git merge second~2 -m "merge-left" &&
81
82 git checkout -b merge-right second~1 &&
83 git merge other~1 -m "merge-right" &&
84
85 git checkout -b octo-second second &&
86 git merge merge-left merge-right -m "octopus-second" &&
87
88 git checkout -b octo-other other &&
89 git merge merge-left merge-right -m "octopus-other" &&
90
91 git checkout other &&
92 git merge octo-other -m "pull octopus" &&
93
c5cd7490 94 git checkout second &&
089f7513
DS
95 git merge octo-second -m "pull octopus" &&
96
97 # Remove these branches so they are not selected
98 # as bitmap tips
99 git branch -D merge-left &&
100 git branch -D merge-right &&
101 git branch -D octo-other &&
102 git branch -D octo-second &&
103
104 # add padding to make these merges less interesting
105 # and avoid having them selected for bitmaps
106 test_commit_bulk --id=file 100 &&
107 git checkout other &&
108 test_commit_bulk --id=side 100 &&
109 git checkout second &&
110
c5cd7490 111 bitmaptip=$(git rev-parse second) &&
212f2ffb
JK
112 blob=$(echo tagged-blob | git hash-object -w --stdin) &&
113 git tag tagged-blob $blob &&
d4316604 114 git config repack.writebitmaps true
212f2ffb
JK
115'
116
117test_expect_success 'full repack creates bitmaps' '
089f7513
DS
118 GIT_TRACE2_EVENT_NESTING=4 GIT_TRACE2_EVENT="$(pwd)/trace" \
119 git repack -ad &&
212f2ffb 120 ls .git/objects/pack/ | grep bitmap >output &&
089f7513
DS
121 test_line_count = 1 output &&
122 grep "\"key\":\"num_selected_commits\",\"value\":\"106\"" trace &&
45f4eeb2 123 grep "\"key\":\"num_maximal_commits\",\"value\":\"107\"" trace
212f2ffb
JK
124'
125
126test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
127 git rev-list --test-bitmap HEAD
128'
129
1467b957
DS
130rev_list_tests_head () {
131 test_expect_success "counting commits via bitmap ($state, $branch)" '
132 git rev-list --count $branch >expect &&
133 git rev-list --use-bitmap-index --count $branch >actual &&
212f2ffb
JK
134 test_cmp expect actual
135 '
136
1467b957
DS
137 test_expect_success "counting partial commits via bitmap ($state, $branch)" '
138 git rev-list --count $branch~5..$branch >expect &&
139 git rev-list --use-bitmap-index --count $branch~5..$branch >actual &&
212f2ffb
JK
140 test_cmp expect actual
141 '
142
1467b957
DS
143 test_expect_success "counting commits with limit ($state, $branch)" '
144 git rev-list --count -n 1 $branch >expect &&
145 git rev-list --use-bitmap-index --count -n 1 $branch >actual &&
5c9f9bf3
JK
146 test_cmp expect actual
147 '
148
1467b957 149 test_expect_success "counting non-linear history ($state, $branch)" '
c5cd7490
JK
150 git rev-list --count other...second >expect &&
151 git rev-list --use-bitmap-index --count other...second >actual &&
212f2ffb
JK
152 test_cmp expect actual
153 '
154
1467b957
DS
155 test_expect_success "counting commits with limiting ($state, $branch)" '
156 git rev-list --count $branch -- 1.t >expect &&
157 git rev-list --use-bitmap-index --count $branch -- 1.t >actual &&
c8a70d35
JK
158 test_cmp expect actual
159 '
160
1467b957
DS
161 test_expect_success "counting objects via bitmap ($state, $branch)" '
162 git rev-list --count --objects $branch >expect &&
163 git rev-list --use-bitmap-index --count --objects $branch >actual &&
608d9c93
JK
164 test_cmp expect actual
165 '
166
1467b957
DS
167 test_expect_success "enumerate commits ($state, $branch)" '
168 git rev-list --use-bitmap-index $branch >actual &&
169 git rev-list $branch >expect &&
4eb707eb
JK
170 test_bitmap_traversal --no-confirm-bitmaps expect actual
171 '
172
1467b957
DS
173 test_expect_success "enumerate --objects ($state, $branch)" '
174 git rev-list --objects --use-bitmap-index $branch >actual &&
175 git rev-list --objects $branch >expect &&
ea047a8e 176 test_bitmap_traversal expect actual
212f2ffb
JK
177 '
178
1467b957
DS
179 test_expect_success "bitmap --objects handles non-commit objects ($state, $branch)" '
180 git rev-list --objects --use-bitmap-index $branch tagged-blob >actual &&
212f2ffb
JK
181 grep $blob actual
182 '
183}
184
1467b957
DS
185rev_list_tests () {
186 state=$1
187
188 for branch in "second" "other"
189 do
190 rev_list_tests_head
191 done
192}
193
212f2ffb
JK
194rev_list_tests 'full bitmap'
195
196test_expect_success 'clone from bitmapped repository' '
197 git clone --no-local --bare . clone.git &&
198 git rev-parse HEAD >expect &&
199 git --git-dir=clone.git rev-parse HEAD >actual &&
200 test_cmp expect actual
201'
202
3ab3185f
JK
203test_expect_success 'partial clone from bitmapped repository' '
204 test_config uploadpack.allowfilter true &&
205 git clone --no-local --bare --filter=blob:none . partial-clone.git &&
206 (
207 cd partial-clone.git &&
208 pack=$(echo objects/pack/*.pack) &&
209 git verify-pack -v "$pack" >have &&
210 awk "/blob/ { print \$1 }" <have >blobs &&
211 # we expect this single blob because of the direct ref
212 git rev-parse refs/tags/tagged-blob >expect &&
213 test_cmp expect blobs
214 )
215'
216
212f2ffb 217test_expect_success 'setup further non-bitmapped commits' '
b1c36cb8 218 test_commit_bulk --id=further 10
212f2ffb
JK
219'
220
221rev_list_tests 'partial bitmap'
222
223test_expect_success 'fetch (partial bitmap)' '
c5cd7490 224 git --git-dir=clone.git fetch origin second:second &&
212f2ffb
JK
225 git rev-parse HEAD >expect &&
226 git --git-dir=clone.git rev-parse HEAD >actual &&
227 test_cmp expect actual
228'
229
1c409a70 230test_expect_success 'incremental repack fails when bitmaps are requested' '
212f2ffb 231 test_commit more-1 &&
1c409a70
DT
232 test_must_fail git repack -d 2>err &&
233 test_i18ngrep "Incremental repacks are incompatible with bitmap" err
212f2ffb
JK
234'
235
236test_expect_success 'incremental repack can disable bitmaps' '
237 test_commit more-2 &&
238 git repack -d --no-write-bitmap-index
239'
240
702d1b95
KS
241test_expect_success 'pack-objects respects --local (non-local loose)' '
242 git init --bare alt.git &&
243 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
244 echo content1 >file1 &&
245 # non-local loose object which is not present in bitmapped pack
246 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
247 # non-local loose object which is also present in bitmapped pack
248 git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
249 git add file1 &&
250 test_tick &&
251 git commit -m commit_file1 &&
252 echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
253 git index-pack 1.pack &&
254 list_packed_objects 1.idx >1.objects &&
255 printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
256 ! has_any nonlocal-loose 1.objects
257'
258
259test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
260 echo content2 >file2 &&
261 blob2=$(git hash-object -w file2) &&
262 git add file2 &&
263 test_tick &&
264 git commit -m commit_file2 &&
265 printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
266 pack2=$(git pack-objects pack2 <keepobjects) &&
267 mv pack2-$pack2.* .git/objects/pack/ &&
268 >.git/objects/pack/pack2-$pack2.keep &&
269 rm $(objpath $blob2) &&
270 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
271 git index-pack 2a.pack &&
272 list_packed_objects 2a.idx >2a.objects &&
273 ! has_any keepobjects 2a.objects
274'
275
276test_expect_success 'pack-objects respects --local (non-local pack)' '
277 mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
278 echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
279 git index-pack 2b.pack &&
280 list_packed_objects 2b.idx >2b.objects &&
281 ! has_any keepobjects 2b.objects
282'
283
284test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
285 ls .git/objects/pack/ | grep bitmap >output &&
286 test_line_count = 1 output &&
287 packbitmap=$(basename $(cat output) .bitmap) &&
288 list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
289 test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
290 >.git/objects/pack/$packbitmap.keep &&
291 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
292 git index-pack 3a.pack &&
293 list_packed_objects 3a.idx >3a.objects &&
294 ! has_any packbitmap.objects 3a.objects
295'
296
297test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
298 mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
0465a505 299 rm -f .git/objects/pack/multi-pack-index &&
702d1b95
KS
300 test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
301 echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
302 git index-pack 3b.pack &&
303 list_packed_objects 3b.idx >3b.objects &&
304 ! has_any packbitmap.objects 3b.objects
305'
306
645c432d
KS
307test_expect_success 'pack-objects to file can use bitmap' '
308 # make sure we still have 1 bitmap index from previous tests
309 ls .git/objects/pack/ | grep bitmap >output &&
310 test_line_count = 1 output &&
311 # verify equivalent packs are generated with/without using bitmap index
312 packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
313 packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
10c60017
SG
314 list_packed_objects packa-$packasha1.idx >packa.objects &&
315 list_packed_objects packb-$packbsha1.idx >packb.objects &&
645c432d
KS
316 test_cmp packa.objects packb.objects
317'
318
212f2ffb
JK
319test_expect_success 'full repack, reusing previous bitmaps' '
320 git repack -ad &&
321 ls .git/objects/pack/ | grep bitmap >output &&
322 test_line_count = 1 output
323'
324
325test_expect_success 'fetch (full bitmap)' '
c5cd7490 326 git --git-dir=clone.git fetch origin second:second &&
212f2ffb
JK
327 git rev-parse HEAD >expect &&
328 git --git-dir=clone.git rev-parse HEAD >actual &&
329 test_cmp expect actual
330'
331
2db1a43f
VM
332test_expect_success 'create objects for missing-HAVE tests' '
333 blob=$(echo "missing have" | git hash-object -w --stdin) &&
334 tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
335 parent=$(echo parent | git commit-tree $tree) &&
336 commit=$(echo commit | git commit-tree $tree -p $parent) &&
337 cat >revs <<-EOF
338 HEAD
339 ^HEAD^
340 ^$commit
341 EOF
342'
343
702d1b95
KS
344test_expect_success 'pack-objects respects --incremental' '
345 cat >revs2 <<-EOF &&
346 HEAD
347 $commit
348 EOF
349 git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
350 git index-pack 4.pack &&
351 list_packed_objects 4.idx >4.objects &&
352 test_line_count = 4 4.objects &&
353 git rev-list --objects $commit >revlist &&
354 cut -d" " -f1 revlist |sort >objects &&
355 test_cmp 4.objects objects
356'
357
2db1a43f
VM
358test_expect_success 'pack with missing blob' '
359 rm $(objpath $blob) &&
360 git pack-objects --stdout --revs <revs >/dev/null
361'
362
363test_expect_success 'pack with missing tree' '
364 rm $(objpath $tree) &&
365 git pack-objects --stdout --revs <revs >/dev/null
366'
367
368test_expect_success 'pack with missing parent' '
369 rm $(objpath $parent) &&
370 git pack-objects --stdout --revs <revs >/dev/null
371'
372
ea699b4a 373test_expect_success JGIT,SHA1 'we can read jgit bitmaps' '
87a6bb70 374 git clone --bare . compat-jgit.git &&
212f2ffb 375 (
87a6bb70 376 cd compat-jgit.git &&
90ca1495 377 rm -f objects/pack/*.bitmap &&
212f2ffb
JK
378 jgit gc &&
379 git rev-list --test-bitmap HEAD
380 )
381'
382
ea699b4a 383test_expect_success JGIT,SHA1 'jgit can read our bitmaps' '
87a6bb70 384 git clone --bare . compat-us.git &&
212f2ffb 385 (
87a6bb70 386 cd compat-us.git &&
212f2ffb
JK
387 git repack -adb &&
388 # jgit gc will barf if it does not like our bitmaps
389 jgit gc
390 )
391'
392
21134714 393test_expect_success 'splitting packs does not generate bogus bitmaps' '
c680668d 394 test-tool genrandom foo $((1024 * 1024)) >rand &&
21134714
JK
395 git add rand &&
396 git commit -m "commit with big file" &&
397 git -c pack.packSizeLimit=500k repack -adb &&
398 git init --bare no-bitmaps.git &&
399 git -C no-bitmaps.git fetch .. HEAD
400'
401
9df4a607
JK
402test_expect_success 'set up reusable pack' '
403 rm -f .git/objects/pack/*.keep &&
404 git repack -adb &&
405 reusable_pack () {
406 git for-each-ref --format="%(objectname)" |
407 git pack-objects --delta-base-offset --revs --stdout "$@"
408 }
409'
410
411test_expect_success 'pack reuse respects --honor-pack-keep' '
412 test_when_finished "rm -f .git/objects/pack/*.keep" &&
da5a1f81
JK
413 for i in .git/objects/pack/*.pack
414 do
9df4a607
JK
415 >${i%.pack}.keep
416 done &&
417 reusable_pack --honor-pack-keep >empty.pack &&
418 git index-pack empty.pack &&
9df4a607 419 git show-index <empty.idx >actual &&
d3c6751b 420 test_must_be_empty actual
9df4a607
JK
421'
422
423test_expect_success 'pack reuse respects --local' '
424 mv .git/objects/pack/* alt.git/objects/pack/ &&
425 test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" &&
426 reusable_pack --local >empty.pack &&
427 git index-pack empty.pack &&
9df4a607 428 git show-index <empty.idx >actual &&
d3c6751b 429 test_must_be_empty actual
9df4a607
JK
430'
431
432test_expect_success 'pack reuse respects --incremental' '
433 reusable_pack --incremental >empty.pack &&
434 git index-pack empty.pack &&
9df4a607 435 git show-index <empty.idx >actual &&
d3c6751b 436 test_must_be_empty actual
9df4a607 437'
9d2e330b 438
ec6c7b43
JK
439test_expect_success 'truncated bitmap fails gracefully (ewah)' '
440 test_config pack.writebitmaphashcache false &&
9d2e330b
JK
441 git repack -ad &&
442 git rev-list --use-bitmap-index --count --all >expect &&
443 bitmap=$(ls .git/objects/pack/*.bitmap) &&
444 test_when_finished "rm -f $bitmap" &&
c5cd7490 445 test_copy_bytes 256 <$bitmap >$bitmap.tmp &&
9d2e330b
JK
446 mv -f $bitmap.tmp $bitmap &&
447 git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
448 test_cmp expect actual &&
ec6c7b43
JK
449 test_i18ngrep corrupt.ewah.bitmap stderr
450'
451
452test_expect_success 'truncated bitmap fails gracefully (cache)' '
9d2e330b
JK
453 git repack -ad &&
454 git rev-list --use-bitmap-index --count --all >expect &&
455 bitmap=$(ls .git/objects/pack/*.bitmap) &&
456 test_when_finished "rm -f $bitmap" &&
2a59a6ef 457 test_copy_bytes 512 <$bitmap >$bitmap.tmp &&
9d2e330b
JK
458 mv -f $bitmap.tmp $bitmap &&
459 git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
460 test_cmp expect actual &&
ec6c7b43 461 test_i18ngrep corrupted.bitmap.index stderr
9d2e330b
JK
462'
463
c0d61dfc
JK
464# have_delta <obj> <expected_base>
465#
466# Note that because this relies on cat-file, it might find _any_ copy of an
467# object in the repository. The caller is responsible for making sure
468# there's only one (e.g., via "repack -ad", or having just fetched a copy).
469have_delta () {
470 echo $2 >expect &&
471 echo $1 | git cat-file --batch-check="%(deltabase)" >actual &&
472 test_cmp expect actual
473}
474
475# Create a state of history with these properties:
476#
477# - refs that allow a client to fetch some new history, while sharing some old
478# history with the server; we use branches delta-reuse-old and
479# delta-reuse-new here
480#
481# - the new history contains an object that is stored on the server as a delta
482# against a base that is in the old history
483#
484# - the base object is not immediately reachable from the tip of the old
485# history; finding it would involve digging down through history we know the
486# other side has
487#
488# This should result in a state where fetching from old->new would not
489# traditionally reuse the on-disk delta (because we'd have to dig to realize
490# that the client has it), but we will do so if bitmaps can tell us cheaply
491# that the other side has it.
492test_expect_success 'set up thin delta-reuse parent' '
493 # This first commit contains the buried base object.
494 test-tool genrandom delta 16384 >file &&
495 git add file &&
496 git commit -m "delta base" &&
497 base=$(git rev-parse --verify HEAD:file) &&
498
499 # These intermediate commits bury the base back in history.
500 # This becomes the "old" state.
501 for i in 1 2 3 4 5
502 do
503 echo $i >file &&
504 git commit -am "intermediate $i" || return 1
505 done &&
506 git branch delta-reuse-old &&
507
508 # And now our new history has a delta against the buried base. Note
509 # that this must be smaller than the original file, since pack-objects
510 # prefers to create deltas from smaller objects to larger.
511 test-tool genrandom delta 16300 >file &&
512 git commit -am "delta result" &&
513 delta=$(git rev-parse --verify HEAD:file) &&
514 git branch delta-reuse-new &&
515
516 # Repack with bitmaps and double check that we have the expected delta
517 # relationship.
518 git repack -adb &&
519 have_delta $delta $base
520'
521
522# Now we can sanity-check the non-bitmap behavior (that the server is not able
523# to reuse the delta). This isn't strictly something we care about, so this
524# test could be scrapped in the future. But it makes sure that the next test is
525# actually triggering the feature we want.
526#
527# Note that our tools for working with on-the-wire "thin" packs are limited. So
528# we actually perform the fetch, retain the resulting pack, and inspect the
529# result.
530test_expect_success 'fetch without bitmaps ignores delta against old base' '
531 test_config pack.usebitmaps false &&
532 test_when_finished "rm -rf client.git" &&
533 git init --bare client.git &&
534 (
535 cd client.git &&
536 git config transfer.unpackLimit 1 &&
537 git fetch .. delta-reuse-old:delta-reuse-old &&
538 git fetch .. delta-reuse-new:delta-reuse-new &&
539 have_delta $delta $ZERO_OID
540 )
541'
542
543# And do the same for the bitmap case, where we do expect to find the delta.
544test_expect_success 'fetch with bitmaps can reuse old base' '
545 test_config pack.usebitmaps true &&
546 test_when_finished "rm -rf client.git" &&
547 git init --bare client.git &&
548 (
549 cd client.git &&
550 git config transfer.unpackLimit 1 &&
551 git fetch .. delta-reuse-old:delta-reuse-old &&
552 git fetch .. delta-reuse-new:delta-reuse-new &&
553 have_delta $delta $base
554 )
555'
556
212f2ffb 557test_done