3 test_description
='multi-pack-indexes'
6 GIT_TEST_MULTI_PACK_INDEX
=0
9 HASH_LEN
=$
(test_oid rawsz
)
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
24 if test $NUM_PACKS -ge 1
26 ls $OBJECT_DIR/pack
/ |
grep idx |
sort
28 printf "object-dir: $OBJECT_DIR\n"
30 test-tool read-midx
$OBJECT_DIR >actual
&&
31 test_cmp expect actual
34 test_expect_success
'setup' '
40 packnameoff sha256:940
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
60 iii
=$
(printf '%03i' $i)
62 test-tool genrandom
"bar" 200 &&
63 test-tool genrandom
"baz $iii" 50
66 test-tool genrandom
"foo"$i 100 &&
67 test-tool genrandom
"foo"$
(( $i + 1 )) 100 &&
68 test-tool genrandom
"foo"$
(( $i + 2 )) 100
72 test-tool genrandom
"$iii" 8192
74 git update-index
--add file_
$iii deep_delta_
$iii wide_delta_
$iii
77 commit_and_list_objects
() {
80 test-tool genrandom
100 8192;
82 git update-index
--add file_101
&&
83 tree
=$
(git write-tree
) &&
84 commit
=$
(git commit-tree
$tree -p HEAD
</dev
/null
) &&
87 git ls-tree
$tree |
sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
89 git
reset --hard $commit
92 test_expect_success
'create objects' '
93 test_commit initial &&
94 for i in $(test_seq 1 5)
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" ]
114 sort <expect
>expect.sorted
&&
115 mv expect.sorted expect
&&
116 sort <actual
>actual.sorted
&&
117 mv actual.sorted actual
119 test_cmp expect actual
122 compare_results_with_midx
() {
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)
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
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
'multi-pack-index *.rev cleanup with --object-dir' '
206 git clone -s repo alternate &&
208 test_when_finished "rm -rf repo alternate" &&
216 ours="alternate/.git/objects/pack/multi-pack-index-123.rev" &&
217 theirs="repo/.git/objects/pack/multi-pack-index-abc.rev" &&
218 touch "$ours" "$theirs" &&
222 git multi-pack-index --object-dir ../repo/.git/objects write
225 # writing a midx in "repo" should not remove the .rev file in the
227 test_path_is_file repo/.git/objects/pack/multi-pack-index &&
228 test_path_is_file $ours &&
229 test_path_is_missing $theirs
232 test_expect_success
'warn on improper hash version' '
233 git init --object-format=sha1 sha1 &&
236 git config core.multiPackIndex true &&
239 git multi-pack-index write &&
240 mv .git/objects/pack/multi-pack-index ../mpi-sha1
242 git init --object-format=sha256 sha256 &&
245 git config core.multiPackIndex true &&
248 git multi-pack-index write &&
249 mv .git/objects/pack/multi-pack-index ../mpi-sha256
253 mv ../mpi-sha256 .git/objects/pack/multi-pack-index &&
255 test_i18ngrep "multi-pack-index hash version 2 does not match version 1" err
259 mv ../mpi-sha1 .git/objects/pack/multi-pack-index &&
261 test_i18ngrep "multi-pack-index hash version 1 does not match version 2" err
265 test_expect_success
'midx picks objects from preferred pack' '
266 test_when_finished rm -rf preferred.git &&
267 git init --bare preferred.git &&
271 a=$(echo "a" | git hash-object -w --stdin) &&
272 b=$(echo "b" | git hash-object -w --stdin) &&
273 c=$(echo "c" | git hash-object -w --stdin) &&
275 # Set up two packs, duplicating the object "B" at different
278 # Note that the "BC" pack (the one we choose as preferred) sorts
279 # lexically after the "AB" pack, meaning that omitting the
280 # --preferred-pack argument would cause this test to fail (since
281 # the MIDX code would select the copy of "b" in the "AB" pack).
282 git pack-objects objects/pack/test-AB <<-EOF &&
286 bc=$(git pack-objects objects/pack/test-BC <<-EOF
292 git multi-pack-index --object-dir=objects \
293 write --preferred-pack=test-BC-$bc.idx 2>err &&
294 test_must_be_empty err &&
296 test-tool read-midx --show-objects objects >out &&
298 ofs=$(git show-index <objects/pack/test-BC-$bc.idx | grep $b |
300 printf "%s %s\tobjects/pack/test-BC-%s.pack\n" \
301 "$b" "$ofs" "$bc" >expect &&
302 grep ^$b out >actual &&
304 test_cmp expect actual
308 test_expect_success
'preferred packs must be non-empty' '
309 test_when_finished rm -rf preferred.git &&
310 git init preferred.git &&
317 empty="$(git pack-objects $objdir/pack/pack </dev/null)" &&
319 test_must_fail git multi-pack-index write \
320 --preferred-pack=pack-$empty.pack 2>err &&
321 grep "with no objects" err
325 test_expect_success
'verify multi-pack-index success' '
326 git multi-pack-index verify --object-dir=$objdir
329 test_expect_success
'verify progress off for redirected stderr' '
330 git multi-pack-index verify --object-dir=$objdir 2>err &&
331 test_line_count = 0 err
334 test_expect_success
'verify force progress on for stderr' '
335 git multi-pack-index verify --object-dir=$objdir --progress 2>err &&
336 test_file_not_empty err
339 test_expect_success
'verify with the --no-progress option' '
340 git multi-pack-index verify --object-dir=$objdir --no-progress 2>err &&
341 test_line_count = 0 err
344 # usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
345 corrupt_midx_and_verify
() {
351 if test -z "$COMMAND"
353 COMMAND
="git multi-pack-index verify --object-dir=$OBJDIR"
355 FILE
=$OBJDIR/pack
/multi-pack-index
&&
357 test_when_finished
mv midx-backup
$FILE &&
358 cp $FILE midx-backup
&&
359 printf "$DATA" |
dd of
="$FILE" bs
=1 seek
="$POS" conv
=notrunc
&&
360 test_must_fail
$COMMAND 2>test_err
&&
361 grep -v "^+" test_err
>err
&&
362 test_i18ngrep
"$GREPSTR" err
365 test_expect_success
'verify bad signature' '
366 corrupt_midx_and_verify 0 "\00" $objdir \
367 "multi-pack-index signature"
372 MIDX_BYTE_OID_VERSION
=5
373 MIDX_BYTE_CHUNK_COUNT
=6
375 MIDX_BYTE_CHUNK_ID
=$MIDX_HEADER_SIZE
376 MIDX_BYTE_CHUNK_OFFSET
=$
(($MIDX_HEADER_SIZE + 4))
378 MIDX_CHUNK_LOOKUP_WIDTH
=12
379 MIDX_OFFSET_PACKNAMES
=$
(($MIDX_HEADER_SIZE + \
380 $MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
381 MIDX_BYTE_PACKNAME_ORDER
=$
(($MIDX_OFFSET_PACKNAMES + 2))
382 MIDX_OFFSET_OID_FANOUT
=$
(($MIDX_OFFSET_PACKNAMES + $
(test_oid packnameoff
)))
383 MIDX_OID_FANOUT_WIDTH
=4
384 MIDX_BYTE_OID_FANOUT_ORDER
=$
((MIDX_OFFSET_OID_FANOUT
+ 250 * $MIDX_OID_FANOUT_WIDTH + $
(test_oid fanoutoff
)))
385 MIDX_OFFSET_OID_LOOKUP
=$
(($MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
386 MIDX_BYTE_OID_LOOKUP
=$
(($MIDX_OFFSET_OID_LOOKUP + 16 * $HASH_LEN))
387 MIDX_OFFSET_OBJECT_OFFSETS
=$
(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
389 MIDX_BYTE_PACK_INT_ID
=$
(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 2))
390 MIDX_BYTE_OFFSET
=$
(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 6))
392 test_expect_success
'verify bad version' '
393 corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
394 "multi-pack-index version"
397 test_expect_success
'verify bad OID version' '
398 corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\03" $objdir \
402 test_expect_success
'verify truncated chunk count' '
403 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\01" $objdir \
404 "final chunk has non-zero id"
407 test_expect_success
'verify extended chunk count' '
408 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\07" $objdir \
409 "terminating chunk id appears earlier than expected"
412 test_expect_success
'verify missing required chunk' '
413 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_ID "\01" $objdir \
417 test_expect_success
'verify invalid chunk offset' '
418 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_OFFSET "\01" $objdir \
419 "improper chunk offset(s)"
422 test_expect_success
'verify packnames out of order' '
423 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \
424 "pack names out of order"
427 test_expect_success
'verify packnames out of order' '
428 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "a" $objdir \
429 "failed to load pack"
432 test_expect_success
'verify oid fanout out of order' '
433 corrupt_midx_and_verify $MIDX_BYTE_OID_FANOUT_ORDER "\01" $objdir \
434 "oid fanout out of order"
437 test_expect_success
'verify oid lookup out of order' '
438 corrupt_midx_and_verify $MIDX_BYTE_OID_LOOKUP "\00" $objdir \
439 "oid lookup out of order"
442 test_expect_success
'verify incorrect pack-int-id' '
443 corrupt_midx_and_verify $MIDX_BYTE_PACK_INT_ID "\07" $objdir \
447 test_expect_success
'verify incorrect offset' '
448 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
449 "incorrect object offset"
452 test_expect_success
'git-fsck incorrect offset' '
453 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
454 "incorrect object offset" \
455 "git -c core.multipackindex=true fsck"
458 test_expect_success
'corrupt MIDX is not reused' '
459 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
460 "incorrect object offset" &&
461 git multi-pack-index write 2>err &&
462 test_i18ngrep checksum.mismatch err &&
463 git multi-pack-index verify
466 test_expect_success
'verify incorrect checksum' '
467 pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 1)) &&
468 corrupt_midx_and_verify $pos "\377" $objdir "incorrect checksum"
471 test_expect_success
'repack progress off for redirected stderr' '
472 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err &&
473 test_line_count = 0 err
476 test_expect_success
'repack force progress on for stderr' '
477 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
478 test_file_not_empty err
481 test_expect_success
'repack with the --no-progress option' '
482 GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
483 test_line_count = 0 err
486 test_expect_success
'repack removes multi-pack-index when deleting packs' '
487 test_path_is_file $objdir/pack/multi-pack-index &&
488 # Set GIT_TEST_MULTI_PACK_INDEX to 0 to avoid writing a new
489 # multi-pack-index after repacking, but set "core.multiPackIndex" to
490 # true so that "git repack" can read the existing MIDX.
491 GIT_TEST_MULTI_PACK_INDEX=0 git -c core.multiPackIndex repack -adf &&
492 test_path_is_missing $objdir/pack/multi-pack-index
495 test_expect_success
'repack preserves multi-pack-index when creating packs' '
497 test_when_finished "rm -fr preserve" &&
500 packdir=.git/objects/pack &&
501 midx=$packdir/multi-pack-index &&
504 pack1=$(git pack-objects --all $packdir/pack) &&
505 touch $packdir/pack-$pack1.keep &&
507 pack2=$(git pack-objects --revs $packdir/pack) &&
508 touch $packdir/pack-$pack2.keep &&
510 git multi-pack-index write &&
511 cp $midx $midx.bak &&
513 cat >pack-input <<-EOF &&
518 pack3=$(git pack-objects --revs $packdir/pack <pack-input) &&
520 pack4=$(git pack-objects --revs $packdir/pack <pack-input) &&
522 GIT_TEST_MULTI_PACK_INDEX=0 git -c core.multiPackIndex repack -ad &&
524 test_path_is_file $packdir/pack-$pack1.pack &&
525 test_path_is_file $packdir/pack-$pack2.pack &&
526 test_path_is_missing $packdir/pack-$pack3.pack &&
527 test_path_is_missing $packdir/pack-$pack4.pack &&
528 test_cmp_bin $midx.bak $midx
532 compare_results_with_midx
"after repack"
534 test_expect_success
'multi-pack-index and pack-bitmap' '
535 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
536 git -c repack.writeBitmaps=true repack -ad &&
537 git multi-pack-index write &&
538 git rev-list --test-bitmap HEAD
541 test_expect_success
'multi-pack-index and alternates' '
542 git init --bare alt.git &&
543 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
544 echo content1 >file1 &&
545 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
546 git cat-file blob $altblob &&
550 compare_results_with_midx
"with alternate (local midx)"
552 test_expect_success
'multi-pack-index in an alternate' '
553 mv .git/objects/pack/* alt.git/objects/pack &&
554 test_commit add_local_objects &&
555 git repack --local &&
556 git multi-pack-index write &&
557 midx_read_expect 1 3 4 $objdir &&
558 git reset --hard HEAD~1 &&
559 rm -f .git/objects/pack/*
562 compare_results_with_midx
"with alternate (remote midx)"
564 # usage: corrupt_data <file> <pos> [<data>]
569 printf "$data" |
dd of
="$file" bs
=1 seek
="$pos" conv
=notrunc
572 # Force 64-bit offsets by manipulating the idx file.
573 # This makes the IDX file _incorrect_ so be careful to clean up after!
574 test_expect_success
'force some 64-bit offsets with pack-objects' '
576 mkdir objects64/pack &&
577 for i in $(test_seq 1 11)
581 commit_and_list_objects &&
582 pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
583 idx64=objects64/pack/test-64-$pack64.idx &&
585 corrupt_data $idx64 $(test_oid idxoff) "\02" &&
586 # objects64 is not a real repository, but can serve as an alternate
587 # anyway so we can write a MIDX into it
589 test_when_finished "rm -fr repo" &&
592 ( cd ../objects64 && pwd ) >.git/objects/info/alternates &&
593 midx64=$(git multi-pack-index --object-dir=../objects64 write)
595 midx_read_expect 1 63 5 objects64 " large-offsets"
598 test_expect_success
'verify multi-pack-index with 64-bit offsets' '
599 git multi-pack-index verify --object-dir=objects64
603 MIDX_OFFSET_OID_FANOUT
=$
((MIDX_OFFSET_PACKNAMES
+ 54))
604 MIDX_OFFSET_OID_LOOKUP
=$
((MIDX_OFFSET_OID_FANOUT
+ 256 * $MIDX_OID_FANOUT_WIDTH))
605 MIDX_OFFSET_OBJECT_OFFSETS
=$
(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
606 MIDX_OFFSET_LARGE_OFFSETS
=$
(($MIDX_OFFSET_OBJECT_OFFSETS + $NUM_OBJECTS * $MIDX_OFFSET_WIDTH))
607 MIDX_BYTE_LARGE_OFFSET
=$
(($MIDX_OFFSET_LARGE_OFFSETS + 3))
609 test_expect_success
'verify incorrect 64-bit offset' '
610 corrupt_midx_and_verify $MIDX_BYTE_LARGE_OFFSET "\07" objects64 \
611 "incorrect object offset"
614 test_expect_success
'setup expire tests' '
619 test-tool genrandom "data" 4096 >large_file.txt &&
620 git update-index --add large_file.txt &&
621 for i in $(test_seq 1 20)
626 git branch B HEAD~8 &&
627 git branch C HEAD~13 &&
628 git branch D HEAD~16 &&
629 git branch E HEAD~18 &&
630 git pack-objects --revs .git/objects/pack/pack-A <<-EOF &&
634 git pack-objects --revs .git/objects/pack/pack-B <<-EOF &&
638 git pack-objects --revs .git/objects/pack/pack-C <<-EOF &&
642 git pack-objects --revs .git/objects/pack/pack-D <<-EOF &&
646 git pack-objects --revs .git/objects/pack/pack-E <<-EOF &&
649 git multi-pack-index write &&
650 cp -r .git/objects/pack .git/objects/pack-backup
654 test_expect_success
'expire does not remove any packs' '
657 ls .git/objects/pack >expect &&
658 git multi-pack-index expire &&
659 ls .git/objects/pack >actual &&
660 test_cmp expect actual
664 test_expect_success
'expire progress off for redirected stderr' '
667 git multi-pack-index expire 2>err &&
668 test_line_count = 0 err
672 test_expect_success
'expire force progress on for stderr' '
675 GIT_PROGRESS_DELAY=0 git multi-pack-index --progress expire 2>err &&
676 test_file_not_empty err
680 test_expect_success
'expire with the --no-progress option' '
683 GIT_PROGRESS_DELAY=0 git multi-pack-index --no-progress expire 2>err &&
684 test_line_count = 0 err
688 test_expect_success
'expire removes unreferenced packs' '
691 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
695 git multi-pack-index write &&
696 ls .git/objects/pack | grep -v -e pack-[AB] >expect &&
697 git multi-pack-index expire &&
698 ls .git/objects/pack >actual &&
699 test_cmp expect actual &&
700 ls .git/objects/pack/ | grep idx >expect-idx &&
701 test-tool read-midx .git/objects | grep idx >actual-midx &&
702 test_cmp expect-idx actual-midx &&
703 git multi-pack-index verify &&
708 test_expect_success
'repack with minimum size does not alter existing packs' '
711 rm -rf .git/objects/pack &&
712 mv .git/objects/pack-backup .git/objects/pack &&
713 test-tool chmtime =-5 .git/objects/pack/pack-D* &&
714 test-tool chmtime =-4 .git/objects/pack/pack-C* &&
715 test-tool chmtime =-3 .git/objects/pack/pack-B* &&
716 test-tool chmtime =-2 .git/objects/pack/pack-A* &&
717 ls .git/objects/pack >expect &&
718 MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
719 git multi-pack-index repack --batch-size=$MINSIZE &&
720 ls .git/objects/pack >actual &&
721 test_cmp expect actual
725 test_expect_success
'repack respects repack.packKeptObjects=false' '
726 test_when_finished rm -f dup/.git/objects/pack/*keep &&
729 ls .git/objects/pack/*idx >idx-list &&
730 test_line_count = 5 idx-list &&
731 ls .git/objects/pack/*.pack | sed "s/\.pack/.keep/" >keep-list &&
732 test_line_count = 5 keep-list &&
733 for keep in $(cat keep-list)
735 touch $keep || return 1
737 git multi-pack-index repack --batch-size=0 &&
738 ls .git/objects/pack/*idx >idx-list &&
739 test_line_count = 5 idx-list &&
740 test-tool read-midx .git/objects | grep idx >midx-list &&
741 test_line_count = 5 midx-list &&
742 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) &&
743 BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) &&
744 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
745 ls .git/objects/pack/*idx >idx-list &&
746 test_line_count = 5 idx-list &&
747 test-tool read-midx .git/objects | grep idx >midx-list &&
748 test_line_count = 5 midx-list
752 test_expect_success
'repack creates a new pack' '
755 ls .git/objects/pack/*idx >idx-list &&
756 test_line_count = 5 idx-list &&
757 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
758 BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
759 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
760 ls .git/objects/pack/*idx >idx-list &&
761 test_line_count = 6 idx-list &&
762 test-tool read-midx .git/objects | grep idx >midx-list &&
763 test_line_count = 6 midx-list
767 test_expect_success
'expire removes repacked packs' '
770 ls -al .git/objects/pack/*pack &&
771 ls -S .git/objects/pack/*pack | head -n 4 >expect &&
772 git multi-pack-index expire &&
773 ls -S .git/objects/pack/*pack >actual &&
774 test_cmp expect actual &&
775 test-tool read-midx .git/objects | grep idx >midx-list &&
776 test_line_count = 4 midx-list
780 test_expect_success
'expire works when adding new packs' '
783 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
787 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
791 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
795 git multi-pack-index write &&
796 git pack-objects --revs .git/objects/pack/a-pack <<-EOF &&
800 git multi-pack-index write &&
801 git pack-objects --revs .git/objects/pack/z-pack <<-EOF &&
804 git multi-pack-index expire &&
805 ls .git/objects/pack/ | grep idx >expect &&
806 test-tool read-midx .git/objects | grep idx >actual &&
807 test_cmp expect actual &&
808 git multi-pack-index verify
812 test_expect_success
'expire respects .keep files' '
815 git pack-objects --revs .git/objects/pack/pack-all <<-EOF &&
818 git multi-pack-index write &&
819 PACKA=$(ls .git/objects/pack/a-pack*\.pack | sed s/\.pack\$//) &&
821 git multi-pack-index expire &&
822 test_path_is_file $PACKA.idx &&
823 test_path_is_file $PACKA.keep &&
824 test_path_is_file $PACKA.pack &&
825 test-tool read-midx .git/objects | grep idx >midx-list &&
826 test_line_count = 2 midx-list
830 test_expect_success
'repack --batch-size=0 repacks everything' '
834 rm .git/objects/pack/*.keep &&
835 ls .git/objects/pack/*idx >idx-list &&
836 test_line_count = 2 idx-list &&
837 git multi-pack-index repack --batch-size=0 &&
838 ls .git/objects/pack/*idx >idx-list &&
839 test_line_count = 3 idx-list &&
840 test-tool read-midx .git/objects | grep idx >midx-list &&
841 test_line_count = 3 midx-list &&
842 git multi-pack-index expire &&
843 ls -al .git/objects/pack/*idx >idx-list &&
844 test_line_count = 1 idx-list &&
845 git multi-pack-index repack --batch-size=0 &&
846 ls -al .git/objects/pack/*idx >new-idx-list &&
847 test_cmp idx-list new-idx-list
851 test_expect_success
'repack --batch-size=<large> repacks everything' '
854 rm .git/objects/pack/*.keep &&
855 ls .git/objects/pack/*idx >idx-list &&
856 test_line_count = 2 idx-list &&
857 git multi-pack-index repack --batch-size=2000000 &&
858 ls .git/objects/pack/*idx >idx-list &&
859 test_line_count = 3 idx-list &&
860 test-tool read-midx .git/objects | grep idx >midx-list &&
861 test_line_count = 3 midx-list &&
862 git multi-pack-index expire &&
863 ls -al .git/objects/pack/*idx >idx-list &&
864 test_line_count = 1 idx-list
868 test_expect_success
'load reverse index when missing .idx, .pack' '
870 test_when_finished "rm -fr repo" &&
874 git config core.multiPackIndex true &&
878 git multi-pack-index write &&
880 git rev-parse HEAD >tip &&
881 pack=$(ls .git/objects/pack/pack-*.pack) &&
882 idx=$(ls .git/objects/pack/pack-*.idx) &&
885 git cat-file --batch-check="%(objectsize:disk)" <tip &&
889 mv $pack $pack.bak &&
890 git cat-file --batch-check="%(objectsize:disk)" <tip
894 test_expect_success
'usage shown without sub-command' '
895 test_expect_code 129 git multi-pack-index 2>err &&
896 ! test_i18ngrep "unrecognized subcommand" err
899 test_expect_success
'complains when run outside of a repository' '
900 nongit test_must_fail git multi-pack-index write 2>err &&
901 grep "not a git repository" err