3 test_description
='multi-pack-indexes'
16 header: 4d494458 1 $NUM_CHUNKS $NUM_PACKS
17 chunks: pack-names oid-fanout oid-lookup object-offsets$EXTRA_CHUNKS
18 num_objects: $NUM_OBJECTS
21 if test $NUM_PACKS -ge 1
23 ls $OBJECT_DIR/pack
/ |
grep idx |
sort
25 printf "object-dir: $OBJECT_DIR\n"
27 test-tool read-midx
$OBJECT_DIR >actual
&&
28 test_cmp expect actual
31 test_expect_success
'setup' '
38 packnameoff sha256:940
45 test_expect_success
'write midx with no packs' '
46 test_when_finished rm -f pack/multi-pack-index &&
47 git multi-pack-index --object-dir=. write &&
48 midx_read_expect 0 0 4 .
53 iii
=$
(printf '%03i' $i)
55 test-tool genrandom
"bar" 200 &&
56 test-tool genrandom
"baz $iii" 50
59 test-tool genrandom
"foo"$i 100 &&
60 test-tool genrandom
"foo"$
(( $i + 1 )) 100 &&
61 test-tool genrandom
"foo"$
(( $i + 2 )) 100
65 test-tool genrandom
"$iii" 8192
67 git update-index
--add file_
$iii deep_delta_
$iii wide_delta_
$iii
70 commit_and_list_objects
() {
73 test-tool genrandom
100 8192;
75 git update-index
--add file_101
&&
76 tree
=$
(git write-tree
) &&
77 commit
=$
(git commit-tree
$tree -p HEAD
</dev
/null
) &&
80 git ls-tree
$tree |
sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
82 git
reset --hard $commit
85 test_expect_success
'create objects' '
86 test_commit initial &&
87 for i in $(test_seq 1 5)
91 commit_and_list_objects
94 test_expect_success
'write midx with one v1 pack' '
95 pack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) &&
96 test_when_finished rm $objdir/pack/test-$pack.pack \
97 $objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index &&
98 git multi-pack-index --object-dir=$objdir write &&
99 midx_read_expect 1 18 4 $objdir
102 midx_git_two_modes
() {
103 git
-c core.multiPackIndex
=false
$1 >expect
&&
104 git
-c core.multiPackIndex
=true
$1 >actual
&&
105 if [ "$2" = "sorted" ]
107 sort <expect
>expect.sorted
&&
108 mv expect.sorted expect
&&
109 sort <actual
>actual.sorted
&&
110 mv actual.sorted actual
112 test_cmp expect actual
115 compare_results_with_midx
() {
117 test_expect_success
"check normal git operations: $MSG" '
118 midx_git_two_modes "rev-list --objects --all" &&
119 midx_git_two_modes "log --raw" &&
120 midx_git_two_modes "count-objects --verbose" &&
121 midx_git_two_modes "cat-file --batch-all-objects --batch-check" &&
122 midx_git_two_modes "cat-file --batch-all-objects --batch-check --unordered" sorted
126 test_expect_success
'write midx with one v2 pack' '
127 git pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list &&
128 git multi-pack-index --object-dir=$objdir write &&
129 midx_read_expect 1 18 4 $objdir
132 compare_results_with_midx
"one v2 pack"
134 test_expect_success
'corrupt idx not opened' '
135 idx=$(test-tool read-midx $objdir | grep "\.idx\$") &&
136 mv $objdir/pack/$idx backup-$idx &&
137 test_when_finished "mv backup-\$idx \$objdir/pack/\$idx" &&
139 # This is the minimum size for a sha-1 based .idx; this lets
140 # us pass perfunctory tests, but anything that actually opens and reads
141 # the idx file will complain.
142 test_copy_bytes 1064 <backup-$idx >$objdir/pack/$idx &&
144 git -c core.multiPackIndex=true rev-list --objects --all 2>err &&
145 test_must_be_empty err
148 test_expect_success
'add more objects' '
149 for i in $(test_seq 6 10)
153 commit_and_list_objects
156 test_expect_success
'write midx with two packs' '
157 git pack-objects --index-version=1 $objdir/pack/test-2 <obj-list &&
158 git multi-pack-index --object-dir=$objdir write &&
159 midx_read_expect 2 34 4 $objdir
162 compare_results_with_midx
"two packs"
164 test_expect_success
'write progress off for redirected stderr' '
165 git multi-pack-index --object-dir=$objdir write 2>err &&
166 test_line_count = 0 err
169 test_expect_success
'write force progress on for stderr' '
170 git multi-pack-index --object-dir=$objdir --progress write 2>err &&
171 test_file_not_empty err
174 test_expect_success
'write with the --no-progress option' '
175 git multi-pack-index --object-dir=$objdir --no-progress write 2>err &&
176 test_line_count = 0 err
179 test_expect_success
'add more packs' '
180 for j in $(test_seq 11 20)
182 generate_objects $j &&
183 commit_and_list_objects &&
184 git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list
188 compare_results_with_midx
"mixed mode (two packs + extra)"
190 test_expect_success
'write midx with twelve packs' '
191 git multi-pack-index --object-dir=$objdir write &&
192 midx_read_expect 12 74 4 $objdir
195 compare_results_with_midx
"twelve packs"
197 test_expect_success
'verify multi-pack-index success' '
198 git multi-pack-index verify --object-dir=$objdir
201 test_expect_success
'verify progress off for redirected stderr' '
202 git multi-pack-index verify --object-dir=$objdir 2>err &&
203 test_line_count = 0 err
206 test_expect_success
'verify force progress on for stderr' '
207 git multi-pack-index verify --object-dir=$objdir --progress 2>err &&
208 test_file_not_empty err
211 test_expect_success
'verify with the --no-progress option' '
212 git multi-pack-index verify --object-dir=$objdir --no-progress 2>err &&
213 test_line_count = 0 err
216 # usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
217 corrupt_midx_and_verify
() {
223 if test -z "$COMMAND"
225 COMMAND
="git multi-pack-index verify --object-dir=$OBJDIR"
227 FILE
=$OBJDIR/pack
/multi-pack-index
&&
229 test_when_finished
mv midx-backup
$FILE &&
230 cp $FILE midx-backup
&&
231 printf "$DATA" |
dd of
="$FILE" bs
=1 seek
="$POS" conv
=notrunc
&&
232 test_must_fail
$COMMAND 2>test_err
&&
233 grep -v "^+" test_err
>err
&&
234 test_i18ngrep
"$GREPSTR" err
237 test_expect_success
'verify bad signature' '
238 corrupt_midx_and_verify 0 "\00" $objdir \
239 "multi-pack-index signature"
242 HASH_LEN
=$
(test_oid rawsz
)
245 MIDX_BYTE_OID_VERSION
=5
246 MIDX_BYTE_CHUNK_COUNT
=6
248 MIDX_BYTE_CHUNK_ID
=$MIDX_HEADER_SIZE
249 MIDX_BYTE_CHUNK_OFFSET
=$
(($MIDX_HEADER_SIZE + 4))
251 MIDX_CHUNK_LOOKUP_WIDTH
=12
252 MIDX_OFFSET_PACKNAMES
=$
(($MIDX_HEADER_SIZE + \
253 $MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
254 MIDX_BYTE_PACKNAME_ORDER
=$
(($MIDX_OFFSET_PACKNAMES + 2))
255 MIDX_OFFSET_OID_FANOUT
=$
(($MIDX_OFFSET_PACKNAMES + $
(test_oid packnameoff
)))
256 MIDX_OID_FANOUT_WIDTH
=4
257 MIDX_BYTE_OID_FANOUT_ORDER
=$
((MIDX_OFFSET_OID_FANOUT
+ 250 * $MIDX_OID_FANOUT_WIDTH + $
(test_oid fanoutoff
)))
258 MIDX_OFFSET_OID_LOOKUP
=$
(($MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
259 MIDX_BYTE_OID_LOOKUP
=$
(($MIDX_OFFSET_OID_LOOKUP + 16 * $HASH_LEN))
260 MIDX_OFFSET_OBJECT_OFFSETS
=$
(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
262 MIDX_BYTE_PACK_INT_ID
=$
(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 2))
263 MIDX_BYTE_OFFSET
=$
(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 6))
265 test_expect_success
'verify bad version' '
266 corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
267 "multi-pack-index version"
270 test_expect_success
'verify bad OID version' '
271 corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\02" $objdir \
275 test_expect_success
'verify truncated chunk count' '
276 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\01" $objdir \
280 test_expect_success
'verify extended chunk count' '
281 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\07" $objdir \
282 "terminating multi-pack-index chunk id appears earlier than expected"
285 test_expect_success
'verify missing required chunk' '
286 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_ID "\01" $objdir \
290 test_expect_success
'verify invalid chunk offset' '
291 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_OFFSET "\01" $objdir \
292 "invalid chunk offset (too large)"
295 test_expect_success
'verify packnames out of order' '
296 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \
297 "pack names out of order"
300 test_expect_success
'verify packnames out of order' '
301 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "a" $objdir \
302 "failed to load pack"
305 test_expect_success
'verify oid fanout out of order' '
306 corrupt_midx_and_verify $MIDX_BYTE_OID_FANOUT_ORDER "\01" $objdir \
307 "oid fanout out of order"
310 test_expect_success
'verify oid lookup out of order' '
311 corrupt_midx_and_verify $MIDX_BYTE_OID_LOOKUP "\00" $objdir \
312 "oid lookup out of order"
315 test_expect_success
'verify incorrect pack-int-id' '
316 corrupt_midx_and_verify $MIDX_BYTE_PACK_INT_ID "\07" $objdir \
320 test_expect_success
'verify incorrect offset' '
321 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
322 "incorrect object offset"
325 test_expect_success
'git-fsck incorrect offset' '
326 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
327 "incorrect object offset" \
328 "git -c core.multipackindex=true fsck"
331 test_expect_success
'repack progress off for redirected stderr' '
332 git multi-pack-index --object-dir=$objdir repack 2>err &&
333 test_line_count = 0 err
336 test_expect_success
'repack force progress on for stderr' '
337 git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
338 test_file_not_empty err
341 test_expect_success
'repack with the --no-progress option' '
342 git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
343 test_line_count = 0 err
346 test_expect_success
'repack removes multi-pack-index' '
347 test_path_is_file $objdir/pack/multi-pack-index &&
348 GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
349 test_path_is_missing $objdir/pack/multi-pack-index
352 compare_results_with_midx
"after repack"
354 test_expect_success
'multi-pack-index and pack-bitmap' '
355 git -c repack.writeBitmaps=true repack -ad &&
356 git multi-pack-index write &&
357 git rev-list --test-bitmap HEAD
360 test_expect_success
'multi-pack-index and alternates' '
361 git init --bare alt.git &&
362 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
363 echo content1 >file1 &&
364 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
365 git cat-file blob $altblob &&
369 compare_results_with_midx
"with alternate (local midx)"
371 test_expect_success
'multi-pack-index in an alternate' '
372 mv .git/objects/pack/* alt.git/objects/pack &&
373 test_commit add_local_objects &&
374 git repack --local &&
375 git multi-pack-index write &&
376 midx_read_expect 1 3 4 $objdir &&
377 git reset --hard HEAD~1 &&
378 rm -f .git/objects/pack/*
381 compare_results_with_midx
"with alternate (remote midx)"
383 # usage: corrupt_data <file> <pos> [<data>]
388 printf "$data" |
dd of
="$file" bs
=1 seek
="$pos" conv
=notrunc
391 # Force 64-bit offsets by manipulating the idx file.
392 # This makes the IDX file _incorrect_ so be careful to clean up after!
393 test_expect_success
'force some 64-bit offsets with pack-objects' '
395 mkdir objects64/pack &&
396 for i in $(test_seq 1 11)
400 commit_and_list_objects &&
401 pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
402 idx64=objects64/pack/test-64-$pack64.idx &&
404 corrupt_data $idx64 $(test_oid idxoff) "\02" &&
405 midx64=$(git multi-pack-index --object-dir=objects64 write) &&
406 midx_read_expect 1 63 5 objects64 " large-offsets"
409 test_expect_success
'verify multi-pack-index with 64-bit offsets' '
410 git multi-pack-index verify --object-dir=objects64
414 MIDX_OFFSET_OID_FANOUT
=$
((MIDX_OFFSET_PACKNAMES
+ 54))
415 MIDX_OFFSET_OID_LOOKUP
=$
((MIDX_OFFSET_OID_FANOUT
+ 256 * $MIDX_OID_FANOUT_WIDTH))
416 MIDX_OFFSET_OBJECT_OFFSETS
=$
(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
417 MIDX_OFFSET_LARGE_OFFSETS
=$
(($MIDX_OFFSET_OBJECT_OFFSETS + $NUM_OBJECTS * $MIDX_OFFSET_WIDTH))
418 MIDX_BYTE_LARGE_OFFSET
=$
(($MIDX_OFFSET_LARGE_OFFSETS + 3))
420 test_expect_success
'verify incorrect 64-bit offset' '
421 corrupt_midx_and_verify $MIDX_BYTE_LARGE_OFFSET "\07" objects64 \
422 "incorrect object offset"
425 test_expect_success
'setup expire tests' '
430 test-tool genrandom "data" 4096 >large_file.txt &&
431 git update-index --add large_file.txt &&
432 for i in $(test_seq 1 20)
437 git branch B HEAD~8 &&
438 git branch C HEAD~13 &&
439 git branch D HEAD~16 &&
440 git branch E HEAD~18 &&
441 git pack-objects --revs .git/objects/pack/pack-A <<-EOF &&
445 git pack-objects --revs .git/objects/pack/pack-B <<-EOF &&
449 git pack-objects --revs .git/objects/pack/pack-C <<-EOF &&
453 git pack-objects --revs .git/objects/pack/pack-D <<-EOF &&
457 git pack-objects --revs .git/objects/pack/pack-E <<-EOF &&
460 git multi-pack-index write &&
461 cp -r .git/objects/pack .git/objects/pack-backup
465 test_expect_success
'expire does not remove any packs' '
468 ls .git/objects/pack >expect &&
469 git multi-pack-index expire &&
470 ls .git/objects/pack >actual &&
471 test_cmp expect actual
475 test_expect_success
'expire progress off for redirected stderr' '
478 git multi-pack-index expire 2>err &&
479 test_line_count = 0 err
483 test_expect_success
'expire force progress on for stderr' '
486 git multi-pack-index --progress expire 2>err &&
487 test_file_not_empty err
491 test_expect_success
'expire with the --no-progress option' '
494 git multi-pack-index --no-progress expire 2>err &&
495 test_line_count = 0 err
499 test_expect_success
'expire removes unreferenced packs' '
502 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
506 git multi-pack-index write &&
507 ls .git/objects/pack | grep -v -e pack-[AB] >expect &&
508 git multi-pack-index expire &&
509 ls .git/objects/pack >actual &&
510 test_cmp expect actual &&
511 ls .git/objects/pack/ | grep idx >expect-idx &&
512 test-tool read-midx .git/objects | grep idx >actual-midx &&
513 test_cmp expect-idx actual-midx &&
514 git multi-pack-index verify &&
519 test_expect_success
'repack with minimum size does not alter existing packs' '
522 rm -rf .git/objects/pack &&
523 mv .git/objects/pack-backup .git/objects/pack &&
524 touch -m -t 201901010000 .git/objects/pack/pack-D* &&
525 touch -m -t 201901010001 .git/objects/pack/pack-C* &&
526 touch -m -t 201901010002 .git/objects/pack/pack-B* &&
527 touch -m -t 201901010003 .git/objects/pack/pack-A* &&
528 ls .git/objects/pack >expect &&
529 MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
530 git multi-pack-index repack --batch-size=$MINSIZE &&
531 ls .git/objects/pack >actual &&
532 test_cmp expect actual
536 test_expect_success
'repack creates a new pack' '
539 ls .git/objects/pack/*idx >idx-list &&
540 test_line_count = 5 idx-list &&
541 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
542 BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
543 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
544 ls .git/objects/pack/*idx >idx-list &&
545 test_line_count = 6 idx-list &&
546 test-tool read-midx .git/objects | grep idx >midx-list &&
547 test_line_count = 6 midx-list
551 test_expect_success
'expire removes repacked packs' '
554 ls -al .git/objects/pack/*pack &&
555 ls -S .git/objects/pack/*pack | head -n 4 >expect &&
556 git multi-pack-index expire &&
557 ls -S .git/objects/pack/*pack >actual &&
558 test_cmp expect actual &&
559 test-tool read-midx .git/objects | grep idx >midx-list &&
560 test_line_count = 4 midx-list
564 test_expect_success
'expire works when adding new packs' '
567 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
571 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
575 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
579 git multi-pack-index write &&
580 git pack-objects --revs .git/objects/pack/a-pack <<-EOF &&
584 git multi-pack-index write &&
585 git pack-objects --revs .git/objects/pack/z-pack <<-EOF &&
588 git multi-pack-index expire &&
589 ls .git/objects/pack/ | grep idx >expect &&
590 test-tool read-midx .git/objects | grep idx >actual &&
591 test_cmp expect actual &&
592 git multi-pack-index verify
596 test_expect_success
'expire respects .keep files' '
599 git pack-objects --revs .git/objects/pack/pack-all <<-EOF &&
602 git multi-pack-index write &&
603 PACKA=$(ls .git/objects/pack/a-pack*\.pack | sed s/\.pack\$//) &&
605 git multi-pack-index expire &&
606 ls -S .git/objects/pack/a-pack* | grep $PACKA >a-pack-files &&
607 test_line_count = 3 a-pack-files &&
608 test-tool read-midx .git/objects | grep idx >midx-list &&
609 test_line_count = 2 midx-list
613 test_expect_success
'repack --batch-size=0 repacks everything' '
616 rm .git/objects/pack/*.keep &&
617 ls .git/objects/pack/*idx >idx-list &&
618 test_line_count = 2 idx-list &&
619 git multi-pack-index repack --batch-size=0 &&
620 ls .git/objects/pack/*idx >idx-list &&
621 test_line_count = 3 idx-list &&
622 test-tool read-midx .git/objects | grep idx >midx-list &&
623 test_line_count = 3 midx-list &&
624 git multi-pack-index expire &&
625 ls -al .git/objects/pack/*idx >idx-list &&
626 test_line_count = 1 idx-list &&
627 git multi-pack-index repack --batch-size=0 &&
628 ls -al .git/objects/pack/*idx >new-idx-list &&
629 test_cmp idx-list new-idx-list