at commit 314b468c

1 #!/bin/sh
2
3 test_description='multi-pack-indexes'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-chunk.sh
7 . "$TEST_DIRECTORY"/lib-midx.sh
8
9 GIT_TEST_MULTI_PACK_INDEX=0
10 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
11 GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0
12 objdir=.git/objects
13
14 HASH_LEN=$(test_oid rawsz)
15
16 midx_read_expect () {
17 NUM_PACKS=$1
18 NUM_OBJECTS=$2
19 NUM_CHUNKS=$3
20 OBJECT_DIR=$4
21 EXTRA_CHUNKS="$5"
22 {
23 cat <<-EOF &&
24 header: 4d494458 1 $HASH_LEN $NUM_CHUNKS $NUM_PACKS
25 chunks: pack-names oid-fanout oid-lookup object-offsets$EXTRA_CHUNKS
26 num_objects: $NUM_OBJECTS
27 packs:
28 EOF
29 if test $NUM_PACKS -ge 1
30 then
31 ls "$OBJECT_DIR"/pack/ | grep idx | sort
32 fi &&
33 printf "object-dir: $OBJECT_DIR\n"
34 } >expect &&
35 test-tool read-midx "$OBJECT_DIR" >actual &&
36 test_cmp expect actual
37 }
38
39 test_expect_success 'setup' '
40 test_oid_cache <<-EOF
41 idxoff sha1:2999
42 idxoff sha256:3739
43
44 packnameoff sha1:652
45 packnameoff sha256:940
46
47 fanoutoff sha1:1
48 fanoutoff sha256:3
49 EOF
50 '
51
52 test_expect_success "don't write midx with no packs" '
53 test_must_fail git multi-pack-index --object-dir=. write &&
54 test_path_is_missing pack/multi-pack-index
55 '
56
57 test_expect_success SHA1 'warn if a midx contains no oid' '
58 cp "$TEST_DIRECTORY"/t5319/no-objects.midx $objdir/pack/multi-pack-index &&
59 test_must_fail git multi-pack-index verify &&
60 rm $objdir/pack/multi-pack-index
61 '
62
63 generate_objects () {
64 i=$1
65 iii=$(printf '%03i' $i)
66 {
67 test-tool genrandom "bar" 200 &&
68 test-tool genrandom "baz $iii" 50
69 } >wide_delta_$iii &&
70 {
71 test-tool genrandom "foo"$i 100 &&
72 test-tool genrandom "foo"$(( $i + 1 )) 100 &&
73 test-tool genrandom "foo"$(( $i + 2 )) 100
74 } >deep_delta_$iii &&
75 {
76 echo $iii &&
77 test-tool genrandom "$iii" 8192
78 } >file_$iii &&
79 git update-index --add file_$iii deep_delta_$iii wide_delta_$iii
80 }
81
82 commit_and_list_objects () {
83 {
84 echo 101 &&
85 test-tool genrandom 100 8192;
86 } >file_101 &&
87 git update-index --add file_101 &&
88 tree=$(git write-tree) &&
89 commit=$(git commit-tree $tree -p HEAD</dev/null) &&
90 {
91 echo $tree &&
92 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
93 } >obj-list &&
94 git reset --hard $commit
95 }
96
97 test_expect_success 'create objects' '
98 test_commit initial &&
99 for i in $(test_seq 1 5)
100 do
101 generate_objects $i || return 1
102 done &&
103 commit_and_list_objects
104 '
105
106 test_expect_success 'write midx with one v1 pack' '
107 pack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) &&
108 test_when_finished rm $objdir/pack/test-$pack.pack \
109 $objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index &&
110 git multi-pack-index --object-dir=$objdir write &&
111 midx_read_expect 1 18 4 $objdir
112 '
113
114 test_expect_success 'write midx with one v2 pack' '
115 git pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list &&
116 git multi-pack-index --object-dir=$objdir write &&
117 midx_read_expect 1 18 4 $objdir
118 '
119
120 compare_results_with_midx "one v2 pack"
121
122 test_expect_success 'corrupt idx reports errors' '
123 idx=$(test-tool read-midx $objdir | grep "\.idx\$") &&
124 mv $objdir/pack/$idx backup-$idx &&
125 test_when_finished "mv backup-\$idx \$objdir/pack/\$idx" &&
126
127 # This is the minimum size for a sha-1 based .idx; this lets
128 # us pass perfunctory tests, but anything that actually opens and reads
129 # the idx file will complain.
130 test_copy_bytes 1064 <backup-$idx >$objdir/pack/$idx &&
131
132 git -c core.multiPackIndex=true rev-list --objects --all 2>err &&
133 test_grep "index unavailable" err
134 '
135
136 test_expect_success 'add more objects' '
137 for i in $(test_seq 6 10)
138 do
139 generate_objects $i || return 1
140 done &&
141 commit_and_list_objects
142 '
143
144 test_expect_success 'write midx with two packs' '
145 git pack-objects --index-version=1 $objdir/pack/test-2 <obj-list &&
146 git multi-pack-index --object-dir=$objdir write &&
147 midx_read_expect 2 34 4 $objdir
148 '
149
150 compare_results_with_midx "two packs"
151
152 test_expect_success 'write midx with --stdin-packs' '
153 rm -fr $objdir/pack/multi-pack-index &&
154
155 idx="$(find $objdir/pack -name "test-2-*.idx")" &&
156 basename "$idx" >in &&
157
158 git multi-pack-index write --stdin-packs <in &&
159
160 test-tool read-midx $objdir | grep "\.idx$" >packs &&
161
162 test_cmp packs in
163 '
164
165 compare_results_with_midx "mixed mode (one pack + extra)"
166
167 test_expect_success 'write with no objects and preferred pack' '
168 test_when_finished "rm -rf empty" &&
169 git init empty &&
170 test_must_fail git -C empty multi-pack-index write \
171 --stdin-packs --preferred-pack=does-not-exist </dev/null 2>err &&
172 cat >expect <<-EOF &&
173 warning: unknown preferred pack: ${SQ}does-not-exist${SQ}
174 error: no pack files to index.
175 EOF
176 test_cmp expect err
177 '
178
179 test_expect_success 'write progress off for redirected stderr' '
180 git multi-pack-index --object-dir=$objdir write 2>err &&
181 test_line_count = 0 err
182 '
183
184 test_expect_success 'write force progress on for stderr' '
185 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --progress 2>err &&
186 test_file_not_empty err
187 '
188
189 test_expect_success 'write with the --no-progress option' '
190 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --no-progress 2>err &&
191 test_line_count = 0 err
192 '
193
194 test_expect_success 'add more packs' '
195 for j in $(test_seq 11 20)
196 do
197 generate_objects $j &&
198 commit_and_list_objects &&
199 git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list || return 1
200 done
201 '
202
203 compare_results_with_midx "mixed mode (two packs + extra)"
204
205 test_expect_success 'write midx with twelve packs' '
206 git multi-pack-index --object-dir=$objdir write &&
207 midx_read_expect 12 74 4 $objdir
208 '
209
210 compare_results_with_midx "twelve packs"
211
212 test_expect_success 'multi-pack-index *.rev cleanup with --object-dir' '
213 git init repo &&
214 git clone -s repo alternate &&
215
216 test_when_finished "rm -rf repo alternate" &&
217
218 (
219 cd repo &&
220 test_commit base &&
221 git repack -d
222 ) &&
223
224 ours="alternate/.git/objects/pack/multi-pack-index-123.rev" &&
225 theirs="repo/.git/objects/pack/multi-pack-index-abc.rev" &&
226 touch "$ours" "$theirs" &&
227
228 (
229 cd alternate &&
230 git multi-pack-index --object-dir ../repo/.git/objects write
231 ) &&
232
233 # writing a midx in "repo" should not remove the .rev file in the
234 # alternate
235 test_path_is_file repo/.git/objects/pack/multi-pack-index &&
236 test_path_is_file $ours &&
237 test_path_is_missing $theirs
238 '
239
240 test_expect_success 'warn on improper hash version' '
241 git init --object-format=sha1 sha1 &&
242 (
243 cd sha1 &&
244 git config core.multiPackIndex true &&
245 test_commit 1 &&
246 git repack -a &&
247 git multi-pack-index write &&
248 mv .git/objects/pack/multi-pack-index ../mpi-sha1
249 ) &&
250 git init --object-format=sha256 sha256 &&
251 (
252 cd sha256 &&
253 git config core.multiPackIndex true &&
254 test_commit 1 &&
255 git repack -a &&
256 git multi-pack-index write &&
257 mv .git/objects/pack/multi-pack-index ../mpi-sha256
258 ) &&
259 (
260 cd sha1 &&
261 mv ../mpi-sha256 .git/objects/pack/multi-pack-index &&
262 git log -1 2>err &&
263 test_grep "multi-pack-index hash version 2 does not match version 1" err
264 ) &&
265 (
266 cd sha256 &&
267 mv ../mpi-sha1 .git/objects/pack/multi-pack-index &&
268 git log -1 2>err &&
269 test_grep "multi-pack-index hash version 1 does not match version 2" err
270 )
271 '
272
273 test_expect_success 'midx picks objects from preferred pack' '
274 test_when_finished rm -rf preferred.git &&
275 git init --bare preferred.git &&
276 (
277 cd preferred.git &&
278
279 a=$(echo "a" | git hash-object -w --stdin) &&
280 b=$(echo "b" | git hash-object -w --stdin) &&
281 c=$(echo "c" | git hash-object -w --stdin) &&
282
283 # Set up two packs, duplicating the object "B" at different
284 # offsets.
285 #
286 # Note that the "BC" pack (the one we choose as preferred) sorts
287 # lexically after the "AB" pack, meaning that omitting the
288 # --preferred-pack argument would cause this test to fail (since
289 # the MIDX code would select the copy of "b" in the "AB" pack).
290 git pack-objects objects/pack/test-AB <<-EOF &&
291 $a
292 $b
293 EOF
294 bc=$(git pack-objects objects/pack/test-BC <<-EOF
295 $b
296 $c
297 EOF
298 ) &&
299
300 git multi-pack-index --object-dir=objects \
301 write --preferred-pack=test-BC-$bc.idx 2>err &&
302 test_must_be_empty err &&
303
304 test-tool read-midx --show-objects objects >out &&
305
306 ofs=$(git show-index <objects/pack/test-BC-$bc.idx | grep $b |
307 cut -d" " -f1) &&
308 printf "%s %s\t./objects/pack/test-BC-%s.pack\n" \
309 "$b" "$ofs" "$bc" >expect &&
310 grep ^$b out >actual &&
311
312 test_cmp expect actual
313 )
314 '
315
316 test_expect_success 'preferred packs must be non-empty' '
317 test_when_finished rm -rf preferred.git &&
318 git init preferred.git &&
319 (
320 cd preferred.git &&
321
322 test_commit base &&
323 git repack -ad &&
324
325 empty="$(git pack-objects $objdir/pack/pack </dev/null)" &&
326
327 test_must_fail git multi-pack-index write \
328 --preferred-pack=pack-$empty.pack 2>err &&
329 test_grep "with no objects" err
330 )
331 '
332
333 test_expect_success 'preferred pack from existing MIDX without bitmaps' '
334 git init preferred-without-bitmaps &&
335 (
336 cd preferred-without-bitmaps &&
337
338 test_commit one &&
339 pack="$(git pack-objects --all $objdir/pack/pack </dev/null)" &&
340
341 git multi-pack-index write &&
342
343 # make another pack so that the subsequent MIDX write
344 # has something to do
345 test_commit two &&
346 git repack -d &&
347
348 # write a new MIDX without bitmaps reusing the singular
349 # pack from the existing MIDX as the preferred pack in
350 # the new MIDX
351 git multi-pack-index write --preferred-pack=pack-$pack.pack
352 )
353 '
354
355 test_expect_success 'preferred pack cannot be determined without bitmap' '
356 test_when_finished "rm -fr preferred-can-be-queried" &&
357 git init preferred-can-be-queried &&
358 (
359 cd preferred-can-be-queried &&
360 test_commit initial &&
361 git repack -Adl --write-midx --no-write-bitmap-index &&
362 test_must_fail test-tool read-midx --preferred-pack .git/objects 2>err &&
363 test_grep "could not determine MIDX preferred pack" err &&
364 git repack -Adl --write-midx --write-bitmap-index &&
365 test-tool read-midx --preferred-pack .git/objects
366 )
367 '
368
369 test_midx_is_retained () {
370 test-tool chmtime =0 .git/objects/pack/multi-pack-index &&
371 ls -l .git/objects/pack/multi-pack-index >expect &&
372 git multi-pack-index write "$@" &&
373 ls -l .git/objects/pack/multi-pack-index >actual &&
374 test_cmp expect actual
375 }
376
377 test_midx_is_rewritten () {
378 test-tool chmtime =0 .git/objects/pack/multi-pack-index &&
379 ls -l .git/objects/pack/multi-pack-index >expect &&
380 git multi-pack-index write "$@" &&
381 ls -l .git/objects/pack/multi-pack-index >actual &&
382 ! test_cmp expect actual
383 }
384
385 test_expect_success 'up-to-date multi-pack-index is retained' '
386 test_when_finished "rm -fr midx-up-to-date" &&
387 git init midx-up-to-date &&
388 (
389 cd midx-up-to-date &&
390
391 # Write the initial pack that contains the most objects.
392 test_commit first &&
393 test_commit second &&
394 git repack -Ad --write-midx &&
395 test_midx_is_retained &&
396
397 # Writing a new bitmap index should cause us to regenerate the MIDX.
398 test_midx_is_rewritten --bitmap &&
399 test_midx_is_retained --bitmap &&
400
401 # Ensure that writing a new packfile causes us to rewrite the index.
402 test_commit incremental &&
403 git repack -d &&
404 test_midx_is_rewritten &&
405 test_midx_is_retained &&
406
407 for pack in .git/objects/pack/*.idx
408 do
409 basename "$pack" || exit 1
410 done >stdin &&
411 test_line_count = 2 stdin &&
412 test_midx_is_retained --stdin-packs <stdin &&
413 head -n1 stdin >stdin.trimmed &&
414 test_midx_is_rewritten --stdin-packs <stdin.trimmed
415 )
416 '
417
418 test_expect_success 'verify multi-pack-index success' '
419 git multi-pack-index verify --object-dir=$objdir
420 '
421
422 test_expect_success 'verify progress off for redirected stderr' '
423 git multi-pack-index verify --object-dir=$objdir 2>err &&
424 test_line_count = 0 err
425 '
426
427 test_expect_success 'verify force progress on for stderr' '
428 git multi-pack-index verify --object-dir=$objdir --progress 2>err &&
429 test_file_not_empty err
430 '
431
432 test_expect_success 'verify with the --no-progress option' '
433 git multi-pack-index verify --object-dir=$objdir --no-progress 2>err &&
434 test_line_count = 0 err
435 '
436
437 # usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
438 corrupt_midx_and_verify() {
439 POS=$1 &&
440 DATA="${2:-\0}" &&
441 OBJDIR=$3 &&
442 GREPSTR="$4" &&
443 COMMAND="$5" &&
444 if test -z "$COMMAND"
445 then
446 COMMAND="git multi-pack-index verify --object-dir=$OBJDIR"
447 fi &&
448 FILE=$OBJDIR/pack/multi-pack-index &&
449 chmod a+w $FILE &&
450 test_when_finished mv midx-backup $FILE &&
451 cp $FILE midx-backup &&
452 printf "$DATA" | dd of="$FILE" bs=1 seek="$POS" conv=notrunc &&
453 test_must_fail $COMMAND 2>test_err &&
454 grep -v "^+" test_err >err &&
455 test_grep "$GREPSTR" err
456 }
457
458 test_expect_success 'verify bad signature' '
459 corrupt_midx_and_verify 0 "\00" $objdir \
460 "multi-pack-index signature"
461 '
462
463 NUM_OBJECTS=74
464 MIDX_BYTE_VERSION=4
465 MIDX_BYTE_OID_VERSION=5
466 MIDX_BYTE_CHUNK_COUNT=6
467 MIDX_HEADER_SIZE=12
468 MIDX_BYTE_CHUNK_ID=$MIDX_HEADER_SIZE
469 MIDX_BYTE_CHUNK_OFFSET=$(($MIDX_HEADER_SIZE + 4))
470 MIDX_NUM_CHUNKS=5
471 MIDX_CHUNK_LOOKUP_WIDTH=12
472 MIDX_OFFSET_PACKNAMES=$(($MIDX_HEADER_SIZE + \
473 $MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
474 MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2))
475 MIDX_OFFSET_OID_FANOUT=$(($MIDX_OFFSET_PACKNAMES + $(test_oid packnameoff)))
476 MIDX_OID_FANOUT_WIDTH=4
477 MIDX_BYTE_OID_FANOUT_ORDER=$((MIDX_OFFSET_OID_FANOUT + 250 * $MIDX_OID_FANOUT_WIDTH + $(test_oid fanoutoff)))
478 MIDX_OFFSET_OID_LOOKUP=$(($MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
479 MIDX_BYTE_OID_LOOKUP=$(($MIDX_OFFSET_OID_LOOKUP + 16 * $HASH_LEN))
480 MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
481 MIDX_OFFSET_WIDTH=8
482 MIDX_BYTE_PACK_INT_ID=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 2))
483 MIDX_BYTE_OFFSET=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 6))
484
485 test_expect_success 'verify bad version' '
486 corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
487 "multi-pack-index version"
488 '
489
490 test_expect_success 'verify bad OID version' '
491 corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\03" $objdir \
492 "hash version"
493 '
494
495 test_expect_success 'verify truncated chunk count' '
496 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\01" $objdir \
497 "final chunk has non-zero id"
498 '
499
500 test_expect_success 'verify extended chunk count' '
501 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\07" $objdir \
502 "terminating chunk id appears earlier than expected"
503 '
504
505 test_expect_success 'verify missing required chunk' '
506 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_ID "\01" $objdir \
507 "required pack-name chunk missing"
508 '
509
510 test_expect_success 'verify invalid chunk offset' '
511 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_OFFSET "\01" $objdir \
512 "improper chunk offset(s)"
513 '
514
515 test_expect_success 'verify missing pack' '
516 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "a" $objdir \
517 "failed to load pack"
518 '
519
520 test_expect_success 'verify oid fanout out of order' '
521 corrupt_midx_and_verify $MIDX_BYTE_OID_FANOUT_ORDER "\01" $objdir \
522 "oid fanout out of order"
523 '
524
525 test_expect_success 'verify oid lookup out of order' '
526 corrupt_midx_and_verify $MIDX_BYTE_OID_LOOKUP "\00" $objdir \
527 "oid lookup out of order"
528 '
529
530 test_expect_success 'verify incorrect pack-int-id' '
531 corrupt_midx_and_verify $MIDX_BYTE_PACK_INT_ID "\07" $objdir \
532 "bad pack-int-id"
533 '
534
535 test_expect_success 'verify incorrect offset' '
536 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
537 "incorrect object offset"
538 '
539
540 test_expect_success 'git-fsck incorrect offset' '
541 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
542 "incorrect object offset" \
543 "git -c core.multiPackIndex=true fsck" &&
544 test_unconfig core.multiPackIndex &&
545 test_must_fail git fsck &&
546 git -c core.multiPackIndex=false fsck
547 '
548
549 test_expect_success 'git fsck shows MIDX output with --progress' '
550 git fsck --progress 2>err &&
551 test_grep "Verifying OID order in multi-pack-index" err &&
552 test_grep "Verifying object offsets" err
553 '
554
555 test_expect_success 'git fsck suppresses MIDX output with --no-progress' '
556 git fsck --no-progress 2>err &&
557 test_grep ! "Verifying OID order in multi-pack-index" err &&
558 test_grep ! "Verifying object offsets" err
559 '
560
561 test_expect_success 'corrupt MIDX is not reused' '
562 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
563 "incorrect object offset" &&
564 git multi-pack-index write 2>err &&
565 test_grep checksum.mismatch err &&
566 git multi-pack-index verify
567 '
568
569 test_expect_success 'verify incorrect checksum' '
570 pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 10)) &&
571 corrupt_midx_and_verify $pos \
572 "\377\377\377\377\377\377\377\377\377\377" \
573 $objdir "incorrect checksum"
574 '
575
576 test_expect_success 'setup for v1-specific fsck tests' '
577 git -c midx.version=1 multi-pack-index write
578 '
579
580 test_expect_success 'verify packnames out of order (v1)' '
581 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \
582 "pack names out of order"
583 '
584
585 test_expect_success 'repack progress off for redirected stderr' '
586 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err &&
587 test_line_count = 0 err
588 '
589
590 test_expect_success 'repack force progress on for stderr' '
591 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --progress 2>err &&
592 test_file_not_empty err
593 '
594
595 test_expect_success 'repack with the --no-progress option' '
596 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --no-progress 2>err &&
597 test_line_count = 0 err
598 '
599
600 test_expect_success 'repack removes multi-pack-index when deleting packs' '
601 test_path_is_file $objdir/pack/multi-pack-index &&
602 # Set GIT_TEST_MULTI_PACK_INDEX to 0 to avoid writing a new
603 # multi-pack-index after repacking, but set "core.multiPackIndex" to
604 # true so that "git repack" can read the existing MIDX.
605 GIT_TEST_MULTI_PACK_INDEX=0 git -c core.multiPackIndex repack -adf &&
606 test_path_is_missing $objdir/pack/multi-pack-index
607 '
608
609 test_expect_success 'repack preserves multi-pack-index when creating packs' '
610 git init preserve &&
611 test_when_finished "rm -fr preserve" &&
612 (
613 cd preserve &&
614 packdir=.git/objects/pack &&
615 midx=$packdir/multi-pack-index &&
616
617 test_commit 1 &&
618 pack1=$(git pack-objects --all $packdir/pack) &&
619 touch $packdir/pack-$pack1.keep &&
620 test_commit 2 &&
621 pack2=$(git pack-objects --revs $packdir/pack) &&
622 touch $packdir/pack-$pack2.keep &&
623
624 git multi-pack-index write &&
625 cp $midx $midx.bak &&
626
627 cat >pack-input <<-EOF &&
628 HEAD
629 ^HEAD~1
630 EOF
631 test_commit 3 &&
632 pack3=$(git pack-objects --revs $packdir/pack <pack-input) &&
633 test_commit 4 &&
634 pack4=$(git pack-objects --revs $packdir/pack <pack-input) &&
635
636 GIT_TEST_MULTI_PACK_INDEX=0 git -c core.multiPackIndex repack -ad &&
637 ls -la $packdir &&
638 test_path_is_file $packdir/pack-$pack1.pack &&
639 test_path_is_file $packdir/pack-$pack2.pack &&
640 test_path_is_missing $packdir/pack-$pack3.pack &&
641 test_path_is_missing $packdir/pack-$pack4.pack &&
642 test_cmp_bin $midx.bak $midx
643 )
644 '
645
646 compare_results_with_midx "after repack"
647
648 test_expect_success 'multi-pack-index and pack-bitmap' '
649 git -c repack.writeBitmaps=true repack -ad &&
650 git multi-pack-index write &&
651 git rev-list --test-bitmap HEAD
652 '
653
654 test_expect_success 'multi-pack-index and alternates' '
655 git init --bare alt.git &&
656 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
657 echo content1 >file1 &&
658 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
659 git cat-file blob $altblob &&
660 git rev-list --all
661 '
662
663 compare_results_with_midx "with alternate (local midx)"
664
665 test_expect_success 'multi-pack-index in an alternate' '
666 mv .git/objects/pack/* alt.git/objects/pack &&
667 test_commit add_local_objects &&
668 git repack --local &&
669 git multi-pack-index write &&
670 midx_read_expect 1 3 4 $objdir &&
671 git reset --hard HEAD~1 &&
672 rm -f .git/objects/pack/*
673 '
674
675 compare_results_with_midx "with alternate (remote midx)"
676
677 # usage: corrupt_data <file> <pos> [<data>]
678 corrupt_data () {
679 file=$1
680 pos=$2
681 data="${3:-\0}"
682 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
683 }
684
685 # Force 64-bit offsets by manipulating the idx file.
686 # This makes the IDX file _incorrect_ so be careful to clean up after!
687 test_expect_success 'force some 64-bit offsets with pack-objects' '
688 mkdir objects64 &&
689 mkdir objects64/pack &&
690 for i in $(test_seq 1 11)
691 do
692 generate_objects 11 || return 1
693 done &&
694 commit_and_list_objects &&
695 pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
696 idx64=objects64/pack/test-64-$pack64.idx &&
697 chmod u+w $idx64 &&
698 corrupt_data $idx64 $(test_oid idxoff) "\02" &&
699 # objects64 is not a real repository, but can serve as an alternate
700 # anyway so we can write a MIDX into it
701 git init repo64 &&
702 (
703 cd repo64 &&
704 ( cd ../objects64 && pwd ) >.git/objects/info/alternates &&
705 midx64=$(git multi-pack-index --object-dir=../objects64 write)
706 ) &&
707 midx_read_expect 1 63 5 "$(pwd)/objects64" " large-offsets"
708 '
709
710 test_expect_success 'verify multi-pack-index with 64-bit offsets' '
711 git -C repo64 multi-pack-index verify --object-dir=../objects64
712 '
713
714 NUM_OBJECTS=63
715 MIDX_OFFSET_OID_FANOUT=$((MIDX_OFFSET_PACKNAMES + 54))
716 MIDX_OFFSET_OID_LOOKUP=$((MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
717 MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
718 MIDX_OFFSET_LARGE_OFFSETS=$(($MIDX_OFFSET_OBJECT_OFFSETS + $NUM_OBJECTS * $MIDX_OFFSET_WIDTH))
719 MIDX_BYTE_LARGE_OFFSET=$(($MIDX_OFFSET_LARGE_OFFSETS + 3))
720
721 test_expect_success 'verify incorrect 64-bit offset' '
722 corrupt_midx_and_verify $MIDX_BYTE_LARGE_OFFSET "\07" objects64 \
723 "incorrect object offset" "git -C repo64 multi-pack-index verify --object-dir=../objects64"
724 '
725
726 test_expect_success 'setup expire tests' '
727 mkdir dup &&
728 (
729 cd dup &&
730 git init &&
731 test-tool genrandom "data" 4096 >large_file.txt &&
732 git update-index --add large_file.txt &&
733 for i in $(test_seq 1 20)
734 do
735 test_commit $i || exit 1
736 done &&
737 git branch A HEAD &&
738 git branch B HEAD~8 &&
739 git branch C HEAD~13 &&
740 git branch D HEAD~16 &&
741 git branch E HEAD~18 &&
742 git pack-objects --revs .git/objects/pack/pack-A <<-EOF &&
743 refs/heads/A
744 ^refs/heads/B
745 EOF
746 git pack-objects --revs .git/objects/pack/pack-B <<-EOF &&
747 refs/heads/B
748 ^refs/heads/C
749 EOF
750 git pack-objects --revs .git/objects/pack/pack-C <<-EOF &&
751 refs/heads/C
752 ^refs/heads/D
753 EOF
754 git pack-objects --revs .git/objects/pack/pack-D <<-EOF &&
755 refs/heads/D
756 ^refs/heads/E
757 EOF
758 git pack-objects --revs .git/objects/pack/pack-E <<-EOF &&
759 refs/heads/E
760 EOF
761 git multi-pack-index write &&
762 cp -r .git/objects/pack .git/objects/pack-backup
763 )
764 '
765
766 test_expect_success 'expire does not remove any packs' '
767 (
768 cd dup &&
769 ls .git/objects/pack >expect &&
770 git multi-pack-index expire &&
771 ls .git/objects/pack >actual &&
772 test_cmp expect actual
773 )
774 '
775
776 test_expect_success 'expire progress off for redirected stderr' '
777 (
778 cd dup &&
779 git multi-pack-index expire 2>err &&
780 test_line_count = 0 err
781 )
782 '
783
784 test_expect_success 'expire force progress on for stderr' '
785 (
786 cd dup &&
787 GIT_PROGRESS_DELAY=0 git multi-pack-index expire --progress 2>err &&
788 test_file_not_empty err
789 )
790 '
791
792 test_expect_success 'expire with the --no-progress option' '
793 (
794 cd dup &&
795 GIT_PROGRESS_DELAY=0 git multi-pack-index expire --no-progress 2>err &&
796 test_line_count = 0 err
797 )
798 '
799
800 test_expect_success 'expire removes unreferenced packs' '
801 (
802 cd dup &&
803 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
804 refs/heads/A
805 ^refs/heads/C
806 EOF
807 git multi-pack-index write &&
808 ls .git/objects/pack | grep -v -e pack-[AB] >expect &&
809 git multi-pack-index expire &&
810 ls .git/objects/pack >actual &&
811 test_cmp expect actual &&
812 ls .git/objects/pack/ | grep idx >expect-idx &&
813 test-tool read-midx .git/objects | grep idx >actual-midx &&
814 test_cmp expect-idx actual-midx &&
815 git multi-pack-index verify &&
816 git fsck
817 )
818 '
819
820 test_expect_success 'repack with minimum size does not alter existing packs' '
821 (
822 cd dup &&
823 rm -rf .git/objects/pack &&
824 mv .git/objects/pack-backup .git/objects/pack &&
825 test-tool chmtime =-5 .git/objects/pack/pack-D* &&
826 test-tool chmtime =-4 .git/objects/pack/pack-C* &&
827 test-tool chmtime =-3 .git/objects/pack/pack-B* &&
828 test-tool chmtime =-2 .git/objects/pack/pack-A* &&
829 ls .git/objects/pack >expect &&
830 MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
831 git multi-pack-index repack --batch-size=$MINSIZE &&
832 ls .git/objects/pack >actual &&
833 test_cmp expect actual
834 )
835 '
836
837 test_expect_success 'repack respects repack.packKeptObjects=false' '
838 test_when_finished rm -f dup/.git/objects/pack/*keep &&
839 (
840 cd dup &&
841 ls .git/objects/pack/*idx >idx-list &&
842 test_line_count = 5 idx-list &&
843 ls .git/objects/pack/*.pack | sed "s/\.pack/.keep/" >keep-list &&
844 test_line_count = 5 keep-list &&
845 for keep in $(cat keep-list)
846 do
847 touch $keep || return 1
848 done &&
849 git multi-pack-index repack --batch-size=0 &&
850 ls .git/objects/pack/*idx >idx-list &&
851 test_line_count = 5 idx-list &&
852 test-tool read-midx .git/objects | grep idx >midx-list &&
853 test_line_count = 5 midx-list &&
854 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) &&
855 BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) &&
856 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
857 ls .git/objects/pack/*idx >idx-list &&
858 test_line_count = 5 idx-list &&
859 test-tool read-midx .git/objects | grep idx >midx-list &&
860 test_line_count = 5 midx-list
861 )
862 '
863
864 test_expect_success 'repack creates a new pack' '
865 (
866 cd dup &&
867 ls .git/objects/pack/*idx >idx-list &&
868 test_line_count = 5 idx-list &&
869 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
870 BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
871 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
872 ls .git/objects/pack/*idx >idx-list &&
873 test_line_count = 6 idx-list &&
874 test-tool read-midx .git/objects | grep idx >midx-list &&
875 test_line_count = 6 midx-list
876 )
877 '
878
879 test_expect_success 'repack (all) ignores cruft pack' '
880 git init repo &&
881 test_when_finished "rm -fr repo" &&
882 (
883 cd repo &&
884
885 test_commit base &&
886 test_commit --no-tag unreachable &&
887
888 git reset --hard base &&
889 git reflog expire --all --expire=all &&
890 git repack --cruft -d &&
891
892 git multi-pack-index write &&
893
894 find $objdir/pack | sort >before &&
895 git multi-pack-index repack --batch-size=0 &&
896 find $objdir/pack | sort >after &&
897
898 test_cmp before after
899 )
900 '
901
902 test_expect_success 'repack (--batch-size) ignores cruft pack' '
903 git init repo &&
904 test_when_finished "rm -fr repo" &&
905 (
906 cd repo &&
907
908 test_commit_bulk 5 &&
909 test_commit --no-tag unreachable &&
910
911 git reset --hard HEAD^ &&
912 git reflog expire --all --expire=all &&
913 git repack --cruft -d &&
914
915 test_commit four &&
916
917 find $objdir/pack -type f -name "*.pack" | sort >before &&
918 git repack -d &&
919 find $objdir/pack -type f -name "*.pack" | sort >after &&
920
921 pack="$(comm -13 before after)" &&
922 test_file_size "$pack" >sz &&
923 # Set --batch-size to twice the size of the pack created
924 # in the previous step, since this is enough to
925 # accommodate it and the cruft pack.
926 #
927 # This means that the MIDX machinery *could* combine the
928 # new and cruft packs together.
929 #
930 # We ensure that it does not below.
931 batch="$((($(cat sz) * 2)))" &&
932
933 git multi-pack-index write &&
934
935 find $objdir/pack | sort >before &&
936 git multi-pack-index repack --batch-size=$batch &&
937 find $objdir/pack | sort >after &&
938
939 test_cmp before after
940 )
941 '
942
943 test_expect_success 'expire removes repacked packs' '
944 (
945 cd dup &&
946 ls -al .git/objects/pack/*pack &&
947 ls -S .git/objects/pack/*pack | head -n 4 >expect &&
948 git multi-pack-index expire &&
949 ls -S .git/objects/pack/*pack >actual &&
950 test_cmp expect actual &&
951 test-tool read-midx .git/objects | grep idx >midx-list &&
952 test_line_count = 4 midx-list
953 )
954 '
955
956 test_expect_success 'expire works when adding new packs' '
957 (
958 cd dup &&
959 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
960 refs/heads/A
961 ^refs/heads/B
962 EOF
963 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
964 refs/heads/B
965 ^refs/heads/C
966 EOF
967 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
968 refs/heads/C
969 ^refs/heads/D
970 EOF
971 git multi-pack-index write &&
972 git pack-objects --revs .git/objects/pack/a-pack <<-EOF &&
973 refs/heads/D
974 ^refs/heads/E
975 EOF
976 git multi-pack-index write &&
977 git pack-objects --revs .git/objects/pack/z-pack <<-EOF &&
978 refs/heads/E
979 EOF
980 git multi-pack-index expire &&
981 ls .git/objects/pack/ | grep idx >expect &&
982 test-tool read-midx .git/objects | grep idx >actual &&
983 test_cmp expect actual &&
984 git multi-pack-index verify
985 )
986 '
987
988 test_expect_success 'expire respects .keep files' '
989 (
990 cd dup &&
991 git pack-objects --revs .git/objects/pack/pack-all <<-EOF &&
992 refs/heads/A
993 EOF
994 git multi-pack-index write &&
995 PACKA=$(ls .git/objects/pack/a-pack*\.pack | sed s/\.pack\$//) &&
996 touch $PACKA.keep &&
997 git multi-pack-index expire &&
998 test_path_is_file $PACKA.idx &&
999 test_path_is_file $PACKA.keep &&
1000 test_path_is_file $PACKA.pack &&
1001 test-tool read-midx .git/objects | grep idx >midx-list &&
1002 test_line_count = 2 midx-list
1003 )
1004 '
1005
1006 test_expect_success 'expiring unreferenced cruft pack retains pack' '
1007 git init repo &&
1008 test_when_finished "rm -fr repo" &&
1009 (
1010 cd repo &&
1011
1012 test_commit base &&
1013 test_commit --no-tag unreachable &&
1014 unreachable=$(git rev-parse HEAD) &&
1015
1016 git reset --hard base &&
1017 git reflog expire --all --expire=all &&
1018 git repack --cruft -d &&
1019 mtimes="$(ls $objdir/pack/pack-*.mtimes)" &&
1020
1021 echo "base..$unreachable" >in &&
1022 pack="$(git pack-objects --revs --delta-base-offset \
1023 $objdir/pack/pack <in)" &&
1024
1025 # Preferring the contents of "$pack" will leave the
1026 # cruft pack unreferenced (ie., none of the objects
1027 # contained in the cruft pack will have their MIDX copy
1028 # selected from the cruft pack).
1029 git multi-pack-index write --preferred-pack="pack-$pack.pack" &&
1030 git multi-pack-index expire &&
1031
1032 test_path_is_file "$mtimes"
1033 )
1034 '
1035
1036 test_expect_success 'repack --batch-size=0 repacks everything' '
1037 cp -r dup dup2 &&
1038 (
1039 cd dup &&
1040 rm .git/objects/pack/*.keep &&
1041 ls .git/objects/pack/*idx >idx-list &&
1042 test_line_count = 2 idx-list &&
1043 git multi-pack-index repack --batch-size=0 &&
1044 ls .git/objects/pack/*idx >idx-list &&
1045 test_line_count = 3 idx-list &&
1046 test-tool read-midx .git/objects | grep idx >midx-list &&
1047 test_line_count = 3 midx-list &&
1048 git multi-pack-index expire &&
1049 ls -al .git/objects/pack/*idx >idx-list &&
1050 test_line_count = 1 idx-list &&
1051 git multi-pack-index repack --batch-size=0 &&
1052 ls -al .git/objects/pack/*idx >new-idx-list &&
1053 test_cmp idx-list new-idx-list
1054 )
1055 '
1056
1057 test_expect_success EXPENSIVE 'repack/expire with many packs' '
1058 cp -r dup many &&
1059 (
1060 cd many &&
1061
1062 for i in $(test_seq 1 100)
1063 do
1064 test_commit extra$i &&
1065 git maintenance run --task=loose-objects || return 1
1066 done &&
1067
1068 git multi-pack-index write &&
1069 git multi-pack-index repack &&
1070 git multi-pack-index expire
1071 )
1072 '
1073
1074 test_expect_success 'repack --batch-size=<large> repacks everything' '
1075 (
1076 cd dup2 &&
1077 rm .git/objects/pack/*.keep &&
1078 ls .git/objects/pack/*idx >idx-list &&
1079 test_line_count = 2 idx-list &&
1080 git multi-pack-index repack --batch-size=2000000 &&
1081 ls .git/objects/pack/*idx >idx-list &&
1082 test_line_count = 3 idx-list &&
1083 test-tool read-midx .git/objects | grep idx >midx-list &&
1084 test_line_count = 3 midx-list &&
1085 git multi-pack-index expire &&
1086 ls -al .git/objects/pack/*idx >idx-list &&
1087 test_line_count = 1 idx-list
1088 )
1089 '
1090
1091 test_expect_success 'repack/expire loop' '
1092 git init repack-expire &&
1093 test_when_finished "rm -fr repack-expire" &&
1094 (
1095 cd repack-expire &&
1096
1097 test_commit_bulk 5 &&
1098
1099 # Create three overlapping pack-files
1100 git rev-list --objects HEAD~3 >in-1 &&
1101 git rev-list --objects HEAD~4..HEAD~2 >in-2 &&
1102 git rev-list --objects HEAD~3..HEAD >in-3 &&
1103
1104 # Create disconnected blobs
1105 obj1=$(git hash-object -w in-1) &&
1106 obj2=$(git hash-object -w in-2) &&
1107 obj3=$(git hash-object -w in-3) &&
1108
1109 echo $obj2 >>in-2 &&
1110 echo $obj3 >>in-3 &&
1111
1112 for i in $(test_seq 3)
1113 do
1114 git pack-objects .git/objects/pack/test-$i <in-$i \
1115 || return 1
1116 done &&
1117
1118 rm -fr .git/objects/pack/pack-* &&
1119 git multi-pack-index write &&
1120
1121 for i in $(test_seq 3)
1122 do
1123 for file in $(ls .git/objects/pack/test-$i*)
1124 do
1125 test-tool chmtime =+$((3600*$i-25000)) $file || return 1
1126 done || return 1
1127 done &&
1128
1129 pack1=$(ls .git/objects/pack/test-1-*.pack) &&
1130 pack2=$(ls .git/objects/pack/test-2-*.pack) &&
1131 pack3=$(ls .git/objects/pack/test-3-*.pack) &&
1132
1133 # Prevent test-1 from being rewritten.
1134 touch "${pack1%.pack}.keep" &&
1135
1136 # This repack-expire loop should repack all non-kept packs
1137 # into a new pack and then delete the old packs.
1138 git multi-pack-index repack &&
1139 git multi-pack-index expire &&
1140
1141 test_path_is_missing $pack3 &&
1142 test_path_is_missing $pack2
1143 )
1144 '
1145
1146 test_expect_success 'load reverse index when missing .idx, .pack' '
1147 git init repo &&
1148 test_when_finished "rm -fr repo" &&
1149 (
1150 cd repo &&
1151
1152 git config core.multiPackIndex true &&
1153
1154 test_commit base &&
1155 git repack -ad &&
1156 git multi-pack-index write &&
1157
1158 git rev-parse HEAD >tip &&
1159 pack=$(ls .git/objects/pack/pack-*.pack) &&
1160 idx=$(ls .git/objects/pack/pack-*.idx) &&
1161
1162 mv $idx $idx.bak &&
1163 git cat-file --batch-check="%(objectsize:disk)" <tip &&
1164
1165 mv $idx.bak $idx &&
1166
1167 mv $pack $pack.bak &&
1168 git cat-file --batch-check="%(objectsize:disk)" <tip &&
1169
1170 test_must_fail git multi-pack-index write 2>err &&
1171 test_grep "could not load pack" err
1172 )
1173 '
1174
1175 test_expect_success 'usage shown without sub-command' '
1176 test_expect_code 129 git multi-pack-index 2>err &&
1177 test_grep ! "unrecognized subcommand" err
1178 '
1179
1180 test_expect_success 'complains when run outside of a repository' '
1181 nongit test_must_fail git multi-pack-index write 2>err &&
1182 test_grep "not a git repository" err
1183 '
1184
1185 test_expect_success 'repack with delta islands' '
1186 git init repo &&
1187 test_when_finished "rm -fr repo" &&
1188 (
1189 cd repo &&
1190
1191 test_commit first &&
1192 git repack &&
1193 test_commit second &&
1194 git repack &&
1195
1196 git multi-pack-index write &&
1197 git -c repack.useDeltaIslands=true multi-pack-index repack
1198 )
1199 '
1200
1201 corrupt_chunk () {
1202 midx=.git/objects/pack/multi-pack-index &&
1203 test_when_finished "rm -rf $midx" &&
1204 git repack -ad --write-midx &&
1205 corrupt_chunk_file $midx "$@"
1206 }
1207
1208 test_expect_success PERL_TEST_HELPERS 'reader notices too-small oid fanout chunk' '
1209 corrupt_chunk OIDF clear 00000000 &&
1210 test_must_fail git log 2>err &&
1211 cat >expect <<-\EOF &&
1212 error: multi-pack-index OID fanout is of the wrong size
1213 fatal: multi-pack-index required OID fanout chunk missing or corrupted
1214 EOF
1215 test_cmp expect err
1216 '
1217
1218 test_expect_success PERL_TEST_HELPERS 'reader notices too-small oid lookup chunk' '
1219 corrupt_chunk OIDL clear 00000000 &&
1220 test_must_fail git log 2>err &&
1221 cat >expect <<-\EOF &&
1222 error: multi-pack-index OID lookup chunk is the wrong size
1223 fatal: multi-pack-index required OID lookup chunk missing or corrupted
1224 EOF
1225 test_cmp expect err
1226 '
1227
1228 test_expect_success PERL_TEST_HELPERS 'reader notices too-small pack names chunk' '
1229 # There is no NUL to terminate the name here, so the
1230 # chunk is too short.
1231 corrupt_chunk PNAM clear 70656666 &&
1232 test_must_fail git log 2>err &&
1233 cat >expect <<-\EOF &&
1234 fatal: multi-pack-index pack-name chunk is too short
1235 EOF
1236 test_cmp expect err
1237 '
1238
1239 test_expect_success PERL_TEST_HELPERS 'reader handles unaligned chunks' '
1240 # A 9-byte PNAM means all of the subsequent chunks
1241 # will no longer be 4-byte aligned, but it is still
1242 # a valid one-pack chunk on its own (it is "foo.pack\0").
1243 corrupt_chunk PNAM clear 666f6f2e7061636b00 &&
1244 git -c core.multipackindex=false log >expect.out &&
1245 git -c core.multipackindex=true log >out 2>err &&
1246 test_cmp expect.out out &&
1247 cat >expect.err <<-\EOF &&
1248 error: chunk id 4f494446 not 4-byte aligned
1249 EOF
1250 test_cmp expect.err err
1251 '
1252
1253 test_expect_success PERL_TEST_HELPERS 'reader notices too-small object offset chunk' '
1254 corrupt_chunk OOFF clear 00000000 &&
1255 test_must_fail git log 2>err &&
1256 cat >expect <<-\EOF &&
1257 error: multi-pack-index object offset chunk is the wrong size
1258 fatal: multi-pack-index required object offsets chunk missing or corrupted
1259 EOF
1260 test_cmp expect err
1261 '
1262
1263 test_expect_success PERL_TEST_HELPERS 'reader bounds-checks large offset table' '
1264 # re-use the objects64 dir here to cheaply get access to a midx
1265 # with large offsets.
1266 git init repo &&
1267 test_when_finished "rm -rf repo" &&
1268 (
1269 cd repo &&
1270 (cd ../objects64 && pwd) >.git/objects/info/alternates &&
1271 git multi-pack-index --object-dir=../objects64 write &&
1272 midx=../objects64/pack/multi-pack-index &&
1273 corrupt_chunk_file $midx LOFF clear &&
1274 # using only %(objectsize) is important here; see the commit
1275 # message for more details
1276 test_must_fail git cat-file --batch-all-objects \
1277 --batch-check="%(objectsize)" 2>err &&
1278 cat >expect <<-\EOF &&
1279 fatal: multi-pack-index large offset out of bounds
1280 EOF
1281 test_cmp expect err
1282 )
1283 '
1284
1285 test_expect_success PERL_TEST_HELPERS 'reader notices too-small revindex chunk' '
1286 # We only get a revindex with bitmaps (and likewise only
1287 # load it when they are asked for).
1288 test_config repack.writeBitmaps true &&
1289 corrupt_chunk RIDX clear 00000000 &&
1290 git -c core.multipackIndex=false rev-list \
1291 --all --use-bitmap-index >expect.out &&
1292 git -c core.multipackIndex=true rev-list \
1293 --all --use-bitmap-index >out 2>err &&
1294 test_cmp expect.out out &&
1295 cat >expect.err <<-\EOF &&
1296 error: multi-pack-index reverse-index chunk is the wrong size
1297 warning: multi-pack bitmap is missing required reverse index
1298 EOF
1299 test_cmp expect.err err
1300 '
1301
1302 test_expect_success PERL_TEST_HELPERS 'reader notices out-of-bounds fanout' '
1303 # This is similar to the out-of-bounds fanout test in t5318. The values
1304 # in adjacent entries should be large but not identical (they
1305 # are used as hi/lo starts for a binary search, which would then abort
1306 # immediately).
1307 corrupt_chunk OIDF 0 $(printf "%02x000000" $(test_seq 0 254)) &&
1308 test_must_fail git log 2>err &&
1309 cat >expect <<-\EOF &&
1310 error: oid fanout out of order: fanout[254] = fe000000 > 5c = fanout[255]
1311 fatal: multi-pack-index required OID fanout chunk missing or corrupted
1312 EOF
1313 test_cmp expect err
1314 '
1315
1316 test_expect_success 'bitmapped packs are stored via the BTMP chunk' '
1317 test_when_finished "rm -fr repo" &&
1318 git init repo &&
1319 (
1320 cd repo &&
1321 git config set maintenance.auto false &&
1322
1323 for i in 1 2 3 4 5
1324 do
1325 test_commit "$i" &&
1326 git repack -d || return 1
1327 done &&
1328
1329 find $objdir/pack -type f -name "*.idx" | xargs -n 1 basename |
1330 sort >packs &&
1331
1332 git multi-pack-index write --stdin-packs <packs &&
1333 test_must_fail test-tool read-midx --bitmap $objdir 2>err &&
1334 cat >expect <<-\EOF &&
1335 error: MIDX does not contain the BTMP chunk
1336 EOF
1337 test_cmp expect err &&
1338
1339 git multi-pack-index write --stdin-packs --bitmap \
1340 --preferred-pack="$(head -n1 <packs)" <packs &&
1341 test-tool read-midx --bitmap $objdir >actual &&
1342 for i in $(test_seq $(wc -l <packs))
1343 do
1344 sed -ne "${i}s/\.idx$/\.pack/p" packs &&
1345 echo " bitmap_pos: $((($i - 1) * 3))" &&
1346 echo " bitmap_nr: 3" || return 1
1347 done >expect &&
1348 test_cmp expect actual
1349 )
1350 '
1351
1352 test_expect_success 'pack.preferBitmapTips interprets patterns as hierarchy' '
1353 git init repo &&
1354 test_when_finished "rm -fr repo" &&
1355 (
1356 cd repo &&
1357
1358 # Create enough commits that not all will receive bitmap
1359 # coverage even if they are all at the tip of some reference.
1360 test_commit_bulk --message="%s" 103 &&
1361 git log --format="create refs/tags/%s %H" HEAD >refs &&
1362 git update-ref --stdin <refs &&
1363
1364 # Create the bitmap via the MIDX.
1365 git repack -adb --write-midx &&
1366 test-tool bitmap list-commits | sort >commits-with-bitmap &&
1367
1368 # Verify that we have at least one commit that did not
1369 # receive a bitmap.
1370 git rev-list HEAD >commits.raw &&
1371 sort <commits.raw >commits &&
1372 comm -13 commits-with-bitmap commits >commits-wo-bitmap &&
1373 test_file_not_empty commits-wo-bitmap &&
1374 commit_id=$(head commits-wo-bitmap) &&
1375 ref_without_bitmap=$(git for-each-ref --points-at="$commit_id" --format="%(refname)") &&
1376
1377 # When passing the full refname we do not expect a bitmap to be
1378 # generated, as it should be interpreted as if a slash was
1379 # appended to the pattern.
1380 rm .git/objects/pack/multi-pack-index* &&
1381 git -c pack.preferBitmapTips="$ref_without_bitmap" repack -adb --write-midx &&
1382 test-tool bitmap list-commits >after &&
1383 test_grep ! "$commit_id" after &&
1384
1385 # But if we pass the parent directory of the ref we should see
1386 # a bitmap.
1387 ref_namespace=$(dirname "$ref_without_bitmap") &&
1388 rm .git/objects/pack/multi-pack-index* &&
1389 git -c pack.preferBitmapTips="$ref_namespace" repack -adb --write-midx &&
1390 test-tool bitmap list-commits >after &&
1391 test_grep "$commit_id" after
1392 )
1393 '
1394
1395 test_done