Git 2.33.8
[git.git] / t / t5319-multi-pack-index.sh
blob3d4d9f10c31b2ff1a0c5bb21458a3ef54113802f
1 #!/bin/sh
3 test_description='multi-pack-indexes'
4 . ./test-lib.sh
6 GIT_TEST_MULTI_PACK_INDEX=0
7 objdir=.git/objects
9 HASH_LEN=$(test_oid rawsz)
11 midx_read_expect () {
12 NUM_PACKS=$1
13 NUM_OBJECTS=$2
14 NUM_CHUNKS=$3
15 OBJECT_DIR=$4
16 EXTRA_CHUNKS="$5"
18 cat <<-EOF &&
19 header: 4d494458 1 $HASH_LEN $NUM_CHUNKS $NUM_PACKS
20 chunks: pack-names oid-fanout oid-lookup object-offsets$EXTRA_CHUNKS
21 num_objects: $NUM_OBJECTS
22 packs:
23 EOF
24 if test $NUM_PACKS -ge 1
25 then
26 ls $OBJECT_DIR/pack/ | grep idx | sort
27 fi &&
28 printf "object-dir: $OBJECT_DIR\n"
29 } >expect &&
30 test-tool read-midx $OBJECT_DIR >actual &&
31 test_cmp expect actual
34 test_expect_success 'setup' '
35 test_oid_cache <<-EOF
36 idxoff sha1:2999
37 idxoff sha256:3739
39 packnameoff sha1:652
40 packnameoff sha256:940
42 fanoutoff sha1:1
43 fanoutoff sha256:3
44 EOF
47 test_expect_success "don't write midx with no packs" '
48 test_must_fail git multi-pack-index --object-dir=. write &&
49 test_path_is_missing pack/multi-pack-index
52 test_expect_success SHA1 'warn if a midx contains no oid' '
53 cp "$TEST_DIRECTORY"/t5319/no-objects.midx $objdir/pack/multi-pack-index &&
54 test_must_fail git multi-pack-index verify &&
55 rm $objdir/pack/multi-pack-index
58 generate_objects () {
59 i=$1
60 iii=$(printf '%03i' $i)
62 test-tool genrandom "bar" 200 &&
63 test-tool genrandom "baz $iii" 50
64 } >wide_delta_$iii &&
66 test-tool genrandom "foo"$i 100 &&
67 test-tool genrandom "foo"$(( $i + 1 )) 100 &&
68 test-tool genrandom "foo"$(( $i + 2 )) 100
69 } >deep_delta_$iii &&
71 echo $iii &&
72 test-tool genrandom "$iii" 8192
73 } >file_$iii &&
74 git update-index --add file_$iii deep_delta_$iii wide_delta_$iii
77 commit_and_list_objects () {
79 echo 101 &&
80 test-tool genrandom 100 8192;
81 } >file_101 &&
82 git update-index --add file_101 &&
83 tree=$(git write-tree) &&
84 commit=$(git commit-tree $tree -p HEAD</dev/null) &&
86 echo $tree &&
87 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
88 } >obj-list &&
89 git reset --hard $commit
92 test_expect_success 'create objects' '
93 test_commit initial &&
94 for i in $(test_seq 1 5)
96 generate_objects $i
97 done &&
98 commit_and_list_objects
101 test_expect_success 'write midx with one v1 pack' '
102 pack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) &&
103 test_when_finished rm $objdir/pack/test-$pack.pack \
104 $objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index &&
105 git multi-pack-index --object-dir=$objdir write &&
106 midx_read_expect 1 18 4 $objdir
109 midx_git_two_modes () {
110 git -c core.multiPackIndex=false $1 >expect &&
111 git -c core.multiPackIndex=true $1 >actual &&
112 if [ "$2" = "sorted" ]
113 then
114 sort <expect >expect.sorted &&
115 mv expect.sorted expect &&
116 sort <actual >actual.sorted &&
117 mv actual.sorted actual
118 fi &&
119 test_cmp expect actual
122 compare_results_with_midx () {
123 MSG=$1
124 test_expect_success "check normal git operations: $MSG" '
125 midx_git_two_modes "rev-list --objects --all" &&
126 midx_git_two_modes "log --raw" &&
127 midx_git_two_modes "count-objects --verbose" &&
128 midx_git_two_modes "cat-file --batch-all-objects --batch-check" &&
129 midx_git_two_modes "cat-file --batch-all-objects --batch-check --unordered" sorted
133 test_expect_success 'write midx with one v2 pack' '
134 git pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list &&
135 git multi-pack-index --object-dir=$objdir write &&
136 midx_read_expect 1 18 4 $objdir
139 compare_results_with_midx "one v2 pack"
141 test_expect_success 'corrupt idx reports errors' '
142 idx=$(test-tool read-midx $objdir | grep "\.idx\$") &&
143 mv $objdir/pack/$idx backup-$idx &&
144 test_when_finished "mv backup-\$idx \$objdir/pack/\$idx" &&
146 # This is the minimum size for a sha-1 based .idx; this lets
147 # us pass perfunctory tests, but anything that actually opens and reads
148 # the idx file will complain.
149 test_copy_bytes 1064 <backup-$idx >$objdir/pack/$idx &&
151 git -c core.multiPackIndex=true rev-list --objects --all 2>err &&
152 grep "index unavailable" err
155 test_expect_success 'add more objects' '
156 for i in $(test_seq 6 10)
158 generate_objects $i
159 done &&
160 commit_and_list_objects
163 test_expect_success 'write midx with two packs' '
164 git pack-objects --index-version=1 $objdir/pack/test-2 <obj-list &&
165 git multi-pack-index --object-dir=$objdir write &&
166 midx_read_expect 2 34 4 $objdir
169 compare_results_with_midx "two packs"
171 test_expect_success 'write progress off for redirected stderr' '
172 git multi-pack-index --object-dir=$objdir write 2>err &&
173 test_line_count = 0 err
176 test_expect_success 'write force progress on for stderr' '
177 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress write 2>err &&
178 test_file_not_empty err
181 test_expect_success 'write with the --no-progress option' '
182 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress write 2>err &&
183 test_line_count = 0 err
186 test_expect_success 'add more packs' '
187 for j in $(test_seq 11 20)
189 generate_objects $j &&
190 commit_and_list_objects &&
191 git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list
192 done
195 compare_results_with_midx "mixed mode (two packs + extra)"
197 test_expect_success 'write midx with twelve packs' '
198 git multi-pack-index --object-dir=$objdir write &&
199 midx_read_expect 12 74 4 $objdir
202 compare_results_with_midx "twelve packs"
204 test_expect_success 'warn on improper hash version' '
205 git init --object-format=sha1 sha1 &&
207 cd sha1 &&
208 git config core.multiPackIndex true &&
209 test_commit 1 &&
210 git repack -a &&
211 git multi-pack-index write &&
212 mv .git/objects/pack/multi-pack-index ../mpi-sha1
213 ) &&
214 git init --object-format=sha256 sha256 &&
216 cd sha256 &&
217 git config core.multiPackIndex true &&
218 test_commit 1 &&
219 git repack -a &&
220 git multi-pack-index write &&
221 mv .git/objects/pack/multi-pack-index ../mpi-sha256
222 ) &&
224 cd sha1 &&
225 mv ../mpi-sha256 .git/objects/pack/multi-pack-index &&
226 git log -1 2>err &&
227 test_i18ngrep "multi-pack-index hash version 2 does not match version 1" err
228 ) &&
230 cd sha256 &&
231 mv ../mpi-sha1 .git/objects/pack/multi-pack-index &&
232 git log -1 2>err &&
233 test_i18ngrep "multi-pack-index hash version 1 does not match version 2" err
237 test_expect_success 'midx picks objects from preferred pack' '
238 test_when_finished rm -rf preferred.git &&
239 git init --bare preferred.git &&
241 cd preferred.git &&
243 a=$(echo "a" | git hash-object -w --stdin) &&
244 b=$(echo "b" | git hash-object -w --stdin) &&
245 c=$(echo "c" | git hash-object -w --stdin) &&
247 # Set up two packs, duplicating the object "B" at different
248 # offsets.
250 # Note that the "BC" pack (the one we choose as preferred) sorts
251 # lexically after the "AB" pack, meaning that omitting the
252 # --preferred-pack argument would cause this test to fail (since
253 # the MIDX code would select the copy of "b" in the "AB" pack).
254 git pack-objects objects/pack/test-AB <<-EOF &&
258 bc=$(git pack-objects objects/pack/test-BC <<-EOF
262 ) &&
264 git multi-pack-index --object-dir=objects \
265 write --preferred-pack=test-BC-$bc.idx 2>err &&
266 test_must_be_empty err &&
268 test-tool read-midx --show-objects objects >out &&
270 ofs=$(git show-index <objects/pack/test-BC-$bc.idx | grep $b |
271 cut -d" " -f1) &&
272 printf "%s %s\tobjects/pack/test-BC-%s.pack\n" \
273 "$b" "$ofs" "$bc" >expect &&
274 grep ^$b out >actual &&
276 test_cmp expect actual
280 test_expect_success 'verify multi-pack-index success' '
281 git multi-pack-index verify --object-dir=$objdir
284 test_expect_success 'verify progress off for redirected stderr' '
285 git multi-pack-index verify --object-dir=$objdir 2>err &&
286 test_line_count = 0 err
289 test_expect_success 'verify force progress on for stderr' '
290 git multi-pack-index verify --object-dir=$objdir --progress 2>err &&
291 test_file_not_empty err
294 test_expect_success 'verify with the --no-progress option' '
295 git multi-pack-index verify --object-dir=$objdir --no-progress 2>err &&
296 test_line_count = 0 err
299 # usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
300 corrupt_midx_and_verify() {
301 POS=$1 &&
302 DATA="${2:-\0}" &&
303 OBJDIR=$3 &&
304 GREPSTR="$4" &&
305 COMMAND="$5" &&
306 if test -z "$COMMAND"
307 then
308 COMMAND="git multi-pack-index verify --object-dir=$OBJDIR"
309 fi &&
310 FILE=$OBJDIR/pack/multi-pack-index &&
311 chmod a+w $FILE &&
312 test_when_finished mv midx-backup $FILE &&
313 cp $FILE midx-backup &&
314 printf "$DATA" | dd of="$FILE" bs=1 seek="$POS" conv=notrunc &&
315 test_must_fail $COMMAND 2>test_err &&
316 grep -v "^+" test_err >err &&
317 test_i18ngrep "$GREPSTR" err
320 test_expect_success 'verify bad signature' '
321 corrupt_midx_and_verify 0 "\00" $objdir \
322 "multi-pack-index signature"
325 NUM_OBJECTS=74
326 MIDX_BYTE_VERSION=4
327 MIDX_BYTE_OID_VERSION=5
328 MIDX_BYTE_CHUNK_COUNT=6
329 MIDX_HEADER_SIZE=12
330 MIDX_BYTE_CHUNK_ID=$MIDX_HEADER_SIZE
331 MIDX_BYTE_CHUNK_OFFSET=$(($MIDX_HEADER_SIZE + 4))
332 MIDX_NUM_CHUNKS=5
333 MIDX_CHUNK_LOOKUP_WIDTH=12
334 MIDX_OFFSET_PACKNAMES=$(($MIDX_HEADER_SIZE + \
335 $MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
336 MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2))
337 MIDX_OFFSET_OID_FANOUT=$(($MIDX_OFFSET_PACKNAMES + $(test_oid packnameoff)))
338 MIDX_OID_FANOUT_WIDTH=4
339 MIDX_BYTE_OID_FANOUT_ORDER=$((MIDX_OFFSET_OID_FANOUT + 250 * $MIDX_OID_FANOUT_WIDTH + $(test_oid fanoutoff)))
340 MIDX_OFFSET_OID_LOOKUP=$(($MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
341 MIDX_BYTE_OID_LOOKUP=$(($MIDX_OFFSET_OID_LOOKUP + 16 * $HASH_LEN))
342 MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
343 MIDX_OFFSET_WIDTH=8
344 MIDX_BYTE_PACK_INT_ID=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 2))
345 MIDX_BYTE_OFFSET=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 6))
347 test_expect_success 'verify bad version' '
348 corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
349 "multi-pack-index version"
352 test_expect_success 'verify bad OID version' '
353 corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\03" $objdir \
354 "hash version"
357 test_expect_success 'verify truncated chunk count' '
358 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\01" $objdir \
359 "final chunk has non-zero id"
362 test_expect_success 'verify extended chunk count' '
363 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\07" $objdir \
364 "terminating chunk id appears earlier than expected"
367 test_expect_success 'verify missing required chunk' '
368 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_ID "\01" $objdir \
369 "missing required"
372 test_expect_success 'verify invalid chunk offset' '
373 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_OFFSET "\01" $objdir \
374 "improper chunk offset(s)"
377 test_expect_success 'verify packnames out of order' '
378 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \
379 "pack names out of order"
382 test_expect_success 'verify packnames out of order' '
383 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "a" $objdir \
384 "failed to load pack"
387 test_expect_success 'verify oid fanout out of order' '
388 corrupt_midx_and_verify $MIDX_BYTE_OID_FANOUT_ORDER "\01" $objdir \
389 "oid fanout out of order"
392 test_expect_success 'verify oid lookup out of order' '
393 corrupt_midx_and_verify $MIDX_BYTE_OID_LOOKUP "\00" $objdir \
394 "oid lookup out of order"
397 test_expect_success 'verify incorrect pack-int-id' '
398 corrupt_midx_and_verify $MIDX_BYTE_PACK_INT_ID "\07" $objdir \
399 "bad pack-int-id"
402 test_expect_success 'verify incorrect offset' '
403 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
404 "incorrect object offset"
407 test_expect_success 'git-fsck incorrect offset' '
408 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
409 "incorrect object offset" \
410 "git -c core.multipackindex=true fsck"
413 test_expect_success 'corrupt MIDX is not reused' '
414 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
415 "incorrect object offset" &&
416 git multi-pack-index write 2>err &&
417 test_i18ngrep checksum.mismatch err &&
418 git multi-pack-index verify
421 test_expect_success 'verify incorrect checksum' '
422 pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 1)) &&
423 corrupt_midx_and_verify $pos "\377" $objdir "incorrect checksum"
426 test_expect_success 'repack progress off for redirected stderr' '
427 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err &&
428 test_line_count = 0 err
431 test_expect_success 'repack force progress on for stderr' '
432 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
433 test_file_not_empty err
436 test_expect_success 'repack with the --no-progress option' '
437 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
438 test_line_count = 0 err
441 test_expect_success 'repack removes multi-pack-index when deleting packs' '
442 test_path_is_file $objdir/pack/multi-pack-index &&
443 # Set GIT_TEST_MULTI_PACK_INDEX to 0 to avoid writing a new
444 # multi-pack-index after repacking, but set "core.multiPackIndex" to
445 # true so that "git repack" can read the existing MIDX.
446 GIT_TEST_MULTI_PACK_INDEX=0 git -c core.multiPackIndex repack -adf &&
447 test_path_is_missing $objdir/pack/multi-pack-index
450 test_expect_success 'repack preserves multi-pack-index when creating packs' '
451 git init preserve &&
452 test_when_finished "rm -fr preserve" &&
454 cd preserve &&
455 packdir=.git/objects/pack &&
456 midx=$packdir/multi-pack-index &&
458 test_commit 1 &&
459 pack1=$(git pack-objects --all $packdir/pack) &&
460 touch $packdir/pack-$pack1.keep &&
461 test_commit 2 &&
462 pack2=$(git pack-objects --revs $packdir/pack) &&
463 touch $packdir/pack-$pack2.keep &&
465 git multi-pack-index write &&
466 cp $midx $midx.bak &&
468 cat >pack-input <<-EOF &&
469 HEAD
470 ^HEAD~1
472 test_commit 3 &&
473 pack3=$(git pack-objects --revs $packdir/pack <pack-input) &&
474 test_commit 4 &&
475 pack4=$(git pack-objects --revs $packdir/pack <pack-input) &&
477 GIT_TEST_MULTI_PACK_INDEX=0 git -c core.multiPackIndex repack -ad &&
478 ls -la $packdir &&
479 test_path_is_file $packdir/pack-$pack1.pack &&
480 test_path_is_file $packdir/pack-$pack2.pack &&
481 test_path_is_missing $packdir/pack-$pack3.pack &&
482 test_path_is_missing $packdir/pack-$pack4.pack &&
483 test_cmp_bin $midx.bak $midx
487 compare_results_with_midx "after repack"
489 test_expect_success 'multi-pack-index and pack-bitmap' '
490 git -c repack.writeBitmaps=true repack -ad &&
491 git multi-pack-index write &&
492 git rev-list --test-bitmap HEAD
495 test_expect_success 'multi-pack-index and alternates' '
496 git init --bare alt.git &&
497 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
498 echo content1 >file1 &&
499 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
500 git cat-file blob $altblob &&
501 git rev-list --all
504 compare_results_with_midx "with alternate (local midx)"
506 test_expect_success 'multi-pack-index in an alternate' '
507 mv .git/objects/pack/* alt.git/objects/pack &&
508 test_commit add_local_objects &&
509 git repack --local &&
510 git multi-pack-index write &&
511 midx_read_expect 1 3 4 $objdir &&
512 git reset --hard HEAD~1 &&
513 rm -f .git/objects/pack/*
516 compare_results_with_midx "with alternate (remote midx)"
518 # usage: corrupt_data <file> <pos> [<data>]
519 corrupt_data () {
520 file=$1
521 pos=$2
522 data="${3:-\0}"
523 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
526 # Force 64-bit offsets by manipulating the idx file.
527 # This makes the IDX file _incorrect_ so be careful to clean up after!
528 test_expect_success 'force some 64-bit offsets with pack-objects' '
529 mkdir objects64 &&
530 mkdir objects64/pack &&
531 for i in $(test_seq 1 11)
533 generate_objects 11
534 done &&
535 commit_and_list_objects &&
536 pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
537 idx64=objects64/pack/test-64-$pack64.idx &&
538 chmod u+w $idx64 &&
539 corrupt_data $idx64 $(test_oid idxoff) "\02" &&
540 midx64=$(git multi-pack-index --object-dir=objects64 write) &&
541 midx_read_expect 1 63 5 objects64 " large-offsets"
544 test_expect_success 'verify multi-pack-index with 64-bit offsets' '
545 git multi-pack-index verify --object-dir=objects64
548 NUM_OBJECTS=63
549 MIDX_OFFSET_OID_FANOUT=$((MIDX_OFFSET_PACKNAMES + 54))
550 MIDX_OFFSET_OID_LOOKUP=$((MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
551 MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
552 MIDX_OFFSET_LARGE_OFFSETS=$(($MIDX_OFFSET_OBJECT_OFFSETS + $NUM_OBJECTS * $MIDX_OFFSET_WIDTH))
553 MIDX_BYTE_LARGE_OFFSET=$(($MIDX_OFFSET_LARGE_OFFSETS + 3))
555 test_expect_success 'verify incorrect 64-bit offset' '
556 corrupt_midx_and_verify $MIDX_BYTE_LARGE_OFFSET "\07" objects64 \
557 "incorrect object offset"
560 test_expect_success 'setup expire tests' '
561 mkdir dup &&
563 cd dup &&
564 git init &&
565 test-tool genrandom "data" 4096 >large_file.txt &&
566 git update-index --add large_file.txt &&
567 for i in $(test_seq 1 20)
569 test_commit $i
570 done &&
571 git branch A HEAD &&
572 git branch B HEAD~8 &&
573 git branch C HEAD~13 &&
574 git branch D HEAD~16 &&
575 git branch E HEAD~18 &&
576 git pack-objects --revs .git/objects/pack/pack-A <<-EOF &&
577 refs/heads/A
578 ^refs/heads/B
580 git pack-objects --revs .git/objects/pack/pack-B <<-EOF &&
581 refs/heads/B
582 ^refs/heads/C
584 git pack-objects --revs .git/objects/pack/pack-C <<-EOF &&
585 refs/heads/C
586 ^refs/heads/D
588 git pack-objects --revs .git/objects/pack/pack-D <<-EOF &&
589 refs/heads/D
590 ^refs/heads/E
592 git pack-objects --revs .git/objects/pack/pack-E <<-EOF &&
593 refs/heads/E
595 git multi-pack-index write &&
596 cp -r .git/objects/pack .git/objects/pack-backup
600 test_expect_success 'expire does not remove any packs' '
602 cd dup &&
603 ls .git/objects/pack >expect &&
604 git multi-pack-index expire &&
605 ls .git/objects/pack >actual &&
606 test_cmp expect actual
610 test_expect_success 'expire progress off for redirected stderr' '
612 cd dup &&
613 git multi-pack-index expire 2>err &&
614 test_line_count = 0 err
618 test_expect_success 'expire force progress on for stderr' '
620 cd dup &&
621 GIT_PROGRESS_DELAY=0 git multi-pack-index --progress expire 2>err &&
622 test_file_not_empty err
626 test_expect_success 'expire with the --no-progress option' '
628 cd dup &&
629 GIT_PROGRESS_DELAY=0 git multi-pack-index --no-progress expire 2>err &&
630 test_line_count = 0 err
634 test_expect_success 'expire removes unreferenced packs' '
636 cd dup &&
637 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
638 refs/heads/A
639 ^refs/heads/C
641 git multi-pack-index write &&
642 ls .git/objects/pack | grep -v -e pack-[AB] >expect &&
643 git multi-pack-index expire &&
644 ls .git/objects/pack >actual &&
645 test_cmp expect actual &&
646 ls .git/objects/pack/ | grep idx >expect-idx &&
647 test-tool read-midx .git/objects | grep idx >actual-midx &&
648 test_cmp expect-idx actual-midx &&
649 git multi-pack-index verify &&
650 git fsck
654 test_expect_success 'repack with minimum size does not alter existing packs' '
656 cd dup &&
657 rm -rf .git/objects/pack &&
658 mv .git/objects/pack-backup .git/objects/pack &&
659 test-tool chmtime =-5 .git/objects/pack/pack-D* &&
660 test-tool chmtime =-4 .git/objects/pack/pack-C* &&
661 test-tool chmtime =-3 .git/objects/pack/pack-B* &&
662 test-tool chmtime =-2 .git/objects/pack/pack-A* &&
663 ls .git/objects/pack >expect &&
664 MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
665 git multi-pack-index repack --batch-size=$MINSIZE &&
666 ls .git/objects/pack >actual &&
667 test_cmp expect actual
671 test_expect_success 'repack respects repack.packKeptObjects=false' '
672 test_when_finished rm -f dup/.git/objects/pack/*keep &&
674 cd dup &&
675 ls .git/objects/pack/*idx >idx-list &&
676 test_line_count = 5 idx-list &&
677 ls .git/objects/pack/*.pack | sed "s/\.pack/.keep/" >keep-list &&
678 test_line_count = 5 keep-list &&
679 for keep in $(cat keep-list)
681 touch $keep || return 1
682 done &&
683 git multi-pack-index repack --batch-size=0 &&
684 ls .git/objects/pack/*idx >idx-list &&
685 test_line_count = 5 idx-list &&
686 test-tool read-midx .git/objects | grep idx >midx-list &&
687 test_line_count = 5 midx-list &&
688 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) &&
689 BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) &&
690 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
691 ls .git/objects/pack/*idx >idx-list &&
692 test_line_count = 5 idx-list &&
693 test-tool read-midx .git/objects | grep idx >midx-list &&
694 test_line_count = 5 midx-list
698 test_expect_success 'repack creates a new pack' '
700 cd dup &&
701 ls .git/objects/pack/*idx >idx-list &&
702 test_line_count = 5 idx-list &&
703 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
704 BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
705 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
706 ls .git/objects/pack/*idx >idx-list &&
707 test_line_count = 6 idx-list &&
708 test-tool read-midx .git/objects | grep idx >midx-list &&
709 test_line_count = 6 midx-list
713 test_expect_success 'expire removes repacked packs' '
715 cd dup &&
716 ls -al .git/objects/pack/*pack &&
717 ls -S .git/objects/pack/*pack | head -n 4 >expect &&
718 git multi-pack-index expire &&
719 ls -S .git/objects/pack/*pack >actual &&
720 test_cmp expect actual &&
721 test-tool read-midx .git/objects | grep idx >midx-list &&
722 test_line_count = 4 midx-list
726 test_expect_success 'expire works when adding new packs' '
728 cd dup &&
729 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
730 refs/heads/A
731 ^refs/heads/B
733 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
734 refs/heads/B
735 ^refs/heads/C
737 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
738 refs/heads/C
739 ^refs/heads/D
741 git multi-pack-index write &&
742 git pack-objects --revs .git/objects/pack/a-pack <<-EOF &&
743 refs/heads/D
744 ^refs/heads/E
746 git multi-pack-index write &&
747 git pack-objects --revs .git/objects/pack/z-pack <<-EOF &&
748 refs/heads/E
750 git multi-pack-index expire &&
751 ls .git/objects/pack/ | grep idx >expect &&
752 test-tool read-midx .git/objects | grep idx >actual &&
753 test_cmp expect actual &&
754 git multi-pack-index verify
758 test_expect_success 'expire respects .keep files' '
760 cd dup &&
761 git pack-objects --revs .git/objects/pack/pack-all <<-EOF &&
762 refs/heads/A
764 git multi-pack-index write &&
765 PACKA=$(ls .git/objects/pack/a-pack*\.pack | sed s/\.pack\$//) &&
766 touch $PACKA.keep &&
767 git multi-pack-index expire &&
768 test_path_is_file $PACKA.idx &&
769 test_path_is_file $PACKA.keep &&
770 test_path_is_file $PACKA.pack &&
771 test-tool read-midx .git/objects | grep idx >midx-list &&
772 test_line_count = 2 midx-list
776 test_expect_success 'repack --batch-size=0 repacks everything' '
777 cp -r dup dup2 &&
779 cd dup &&
780 rm .git/objects/pack/*.keep &&
781 ls .git/objects/pack/*idx >idx-list &&
782 test_line_count = 2 idx-list &&
783 git multi-pack-index repack --batch-size=0 &&
784 ls .git/objects/pack/*idx >idx-list &&
785 test_line_count = 3 idx-list &&
786 test-tool read-midx .git/objects | grep idx >midx-list &&
787 test_line_count = 3 midx-list &&
788 git multi-pack-index expire &&
789 ls -al .git/objects/pack/*idx >idx-list &&
790 test_line_count = 1 idx-list &&
791 git multi-pack-index repack --batch-size=0 &&
792 ls -al .git/objects/pack/*idx >new-idx-list &&
793 test_cmp idx-list new-idx-list
797 test_expect_success 'repack --batch-size=<large> repacks everything' '
799 cd dup2 &&
800 rm .git/objects/pack/*.keep &&
801 ls .git/objects/pack/*idx >idx-list &&
802 test_line_count = 2 idx-list &&
803 git multi-pack-index repack --batch-size=2000000 &&
804 ls .git/objects/pack/*idx >idx-list &&
805 test_line_count = 3 idx-list &&
806 test-tool read-midx .git/objects | grep idx >midx-list &&
807 test_line_count = 3 midx-list &&
808 git multi-pack-index expire &&
809 ls -al .git/objects/pack/*idx >idx-list &&
810 test_line_count = 1 idx-list
814 test_expect_success 'load reverse index when missing .idx, .pack' '
815 git init repo &&
816 test_when_finished "rm -fr repo" &&
818 cd repo &&
820 git config core.multiPackIndex true &&
822 test_commit base &&
823 git repack -ad &&
824 git multi-pack-index write &&
826 git rev-parse HEAD >tip &&
827 pack=$(ls .git/objects/pack/pack-*.pack) &&
828 idx=$(ls .git/objects/pack/pack-*.idx) &&
830 mv $idx $idx.bak &&
831 git cat-file --batch-check="%(objectsize:disk)" <tip &&
833 mv $idx.bak $idx &&
835 mv $pack $pack.bak &&
836 git cat-file --batch-check="%(objectsize:disk)" <tip
840 test_expect_success 'usage shown without sub-command' '
841 test_expect_code 129 git multi-pack-index 2>err &&
842 ! test_i18ngrep "unrecognized subcommand" err
845 test_done