]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5319-multi-pack-index.sh
The sixth batch
[thirdparty/git.git] / t / t5319-multi-pack-index.sh
CommitLineData
a3407730
DS
1#!/bin/sh
2
3test_description='multi-pack-indexes'
4. ./test-lib.sh
5
c4d25228
DS
6objdir=.git/objects
7
4d80560c 8midx_read_expect () {
396f2570 9 NUM_PACKS=$1
d7cacf29 10 NUM_OBJECTS=$2
662148c4
DS
11 NUM_CHUNKS=$3
12 OBJECT_DIR=$4
13 EXTRA_CHUNKS="$5"
3227565c
DS
14 {
15 cat <<-EOF &&
662148c4
DS
16 header: 4d494458 1 $NUM_CHUNKS $NUM_PACKS
17 chunks: pack-names oid-fanout oid-lookup object-offsets$EXTRA_CHUNKS
d7cacf29 18 num_objects: $NUM_OBJECTS
3227565c
DS
19 packs:
20 EOF
21 if test $NUM_PACKS -ge 1
22 then
662148c4 23 ls $OBJECT_DIR/pack/ | grep idx | sort
3227565c 24 fi &&
662148c4 25 printf "object-dir: $OBJECT_DIR\n"
3227565c 26 } >expect &&
662148c4 27 test-tool read-midx $OBJECT_DIR >actual &&
4d80560c
DS
28 test_cmp expect actual
29}
30
3c5e65ca 31test_expect_success 'setup' '
32 test_oid_init &&
33 test_oid_cache <<-EOF
34 idxoff sha1:2999
35 idxoff sha256:3739
36
37 packnameoff sha1:652
38 packnameoff sha256:940
39
40 fanoutoff sha1:1
41 fanoutoff sha256:3
42 EOF
43'
44
796d61cd
DR
45test_expect_success "don't write midx with no packs" '
46 test_must_fail git multi-pack-index --object-dir=. write &&
47 test_path_is_missing pack/multi-pack-index
48'
49
50test_expect_success "Warn if a midx contains no oid" '
51 cp "$TEST_DIRECTORY"/t5319/no-objects.midx $objdir/pack/multi-pack-index &&
52 test_must_fail git multi-pack-index verify &&
53 rm $objdir/pack/multi-pack-index
a3407730
DS
54'
55
2c381335
DS
56generate_objects () {
57 i=$1
58 iii=$(printf '%03i' $i)
59 {
60 test-tool genrandom "bar" 200 &&
61 test-tool genrandom "baz $iii" 50
62 } >wide_delta_$iii &&
63 {
64 test-tool genrandom "foo"$i 100 &&
65 test-tool genrandom "foo"$(( $i + 1 )) 100 &&
66 test-tool genrandom "foo"$(( $i + 2 )) 100
67 } >deep_delta_$iii &&
68 {
69 echo $iii &&
70 test-tool genrandom "$iii" 8192
71 } >file_$iii &&
72 git update-index --add file_$iii deep_delta_$iii wide_delta_$iii
73}
74
75commit_and_list_objects () {
76 {
77 echo 101 &&
78 test-tool genrandom 100 8192;
79 } >file_101 &&
80 git update-index --add file_101 &&
81 tree=$(git write-tree) &&
82 commit=$(git commit-tree $tree -p HEAD</dev/null) &&
83 {
84 echo $tree &&
85 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
86 } >obj-list &&
87 git reset --hard $commit
88}
89
90test_expect_success 'create objects' '
91 test_commit initial &&
92 for i in $(test_seq 1 5)
93 do
94 generate_objects $i
95 done &&
96 commit_and_list_objects
97'
98
99test_expect_success 'write midx with one v1 pack' '
c4d25228
DS
100 pack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) &&
101 test_when_finished rm $objdir/pack/test-$pack.pack \
102 $objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index &&
103 git multi-pack-index --object-dir=$objdir write &&
104 midx_read_expect 1 18 4 $objdir
2c381335
DS
105'
106
c4d25228 107midx_git_two_modes () {
b4a14394
JK
108 git -c core.multiPackIndex=false $1 >expect &&
109 git -c core.multiPackIndex=true $1 >actual &&
e9ab2ed7
DS
110 if [ "$2" = "sorted" ]
111 then
b4a14394
JK
112 sort <expect >expect.sorted &&
113 mv expect.sorted expect &&
114 sort <actual >actual.sorted &&
115 mv actual.sorted actual
e9ab2ed7 116 fi &&
c4d25228
DS
117 test_cmp expect actual
118}
119
120compare_results_with_midx () {
121 MSG=$1
122 test_expect_success "check normal git operations: $MSG" '
123 midx_git_two_modes "rev-list --objects --all" &&
e9ab2ed7
DS
124 midx_git_two_modes "log --raw" &&
125 midx_git_two_modes "count-objects --verbose" &&
5670ad98
JK
126 midx_git_two_modes "cat-file --batch-all-objects --batch-check" &&
127 midx_git_two_modes "cat-file --batch-all-objects --batch-check --unordered" sorted
c4d25228
DS
128 '
129}
130
2c381335 131test_expect_success 'write midx with one v2 pack' '
c4d25228
DS
132 git pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list &&
133 git multi-pack-index --object-dir=$objdir write &&
134 midx_read_expect 1 18 4 $objdir
2c381335
DS
135'
136
c4d25228
DS
137compare_results_with_midx "one v2 pack"
138
fc789156
JK
139test_expect_success 'corrupt idx not opened' '
140 idx=$(test-tool read-midx $objdir | grep "\.idx\$") &&
141 mv $objdir/pack/$idx backup-$idx &&
142 test_when_finished "mv backup-\$idx \$objdir/pack/\$idx" &&
143
144 # This is the minimum size for a sha-1 based .idx; this lets
145 # us pass perfunctory tests, but anything that actually opens and reads
146 # the idx file will complain.
147 test_copy_bytes 1064 <backup-$idx >$objdir/pack/$idx &&
148
149 git -c core.multiPackIndex=true rev-list --objects --all 2>err &&
150 test_must_be_empty err
151'
152
2c381335
DS
153test_expect_success 'add more objects' '
154 for i in $(test_seq 6 10)
155 do
156 generate_objects $i
157 done &&
158 commit_and_list_objects
159'
160
161test_expect_success 'write midx with two packs' '
c4d25228
DS
162 git pack-objects --index-version=1 $objdir/pack/test-2 <obj-list &&
163 git multi-pack-index --object-dir=$objdir write &&
164 midx_read_expect 2 34 4 $objdir
2c381335
DS
165'
166
c4d25228
DS
167compare_results_with_midx "two packs"
168
680cba2c
WB
169test_expect_success 'write progress off for redirected stderr' '
170 git multi-pack-index --object-dir=$objdir write 2>err &&
171 test_line_count = 0 err
172'
173
174test_expect_success 'write force progress on for stderr' '
175 git multi-pack-index --object-dir=$objdir --progress write 2>err &&
176 test_file_not_empty err
177'
178
179test_expect_success 'write with the --no-progress option' '
180 git multi-pack-index --object-dir=$objdir --no-progress write 2>err &&
181 test_line_count = 0 err
182'
183
2c381335
DS
184test_expect_success 'add more packs' '
185 for j in $(test_seq 11 20)
186 do
187 generate_objects $j &&
188 commit_and_list_objects &&
c4d25228 189 git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list
2c381335
DS
190 done
191'
192
c4d25228
DS
193compare_results_with_midx "mixed mode (two packs + extra)"
194
2c381335 195test_expect_success 'write midx with twelve packs' '
c4d25228
DS
196 git multi-pack-index --object-dir=$objdir write &&
197 midx_read_expect 12 74 4 $objdir
662148c4
DS
198'
199
c4d25228
DS
200compare_results_with_midx "twelve packs"
201
56ee7ff1
DS
202test_expect_success 'verify multi-pack-index success' '
203 git multi-pack-index verify --object-dir=$objdir
204'
205
680cba2c
WB
206test_expect_success 'verify progress off for redirected stderr' '
207 git multi-pack-index verify --object-dir=$objdir 2>err &&
208 test_line_count = 0 err
209'
210
211test_expect_success 'verify force progress on for stderr' '
212 git multi-pack-index verify --object-dir=$objdir --progress 2>err &&
213 test_file_not_empty err
214'
215
216test_expect_success 'verify with the --no-progress option' '
217 git multi-pack-index verify --object-dir=$objdir --no-progress 2>err &&
218 test_line_count = 0 err
219'
220
53ad0407
DS
221# usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
222corrupt_midx_and_verify() {
223 POS=$1 &&
224 DATA="${2:-\0}" &&
225 OBJDIR=$3 &&
226 GREPSTR="$4" &&
66ec0390
DS
227 COMMAND="$5" &&
228 if test -z "$COMMAND"
229 then
230 COMMAND="git multi-pack-index verify --object-dir=$OBJDIR"
231 fi &&
53ad0407
DS
232 FILE=$OBJDIR/pack/multi-pack-index &&
233 chmod a+w $FILE &&
234 test_when_finished mv midx-backup $FILE &&
235 cp $FILE midx-backup &&
236 printf "$DATA" | dd of="$FILE" bs=1 seek="$POS" conv=notrunc &&
66ec0390 237 test_must_fail $COMMAND 2>test_err &&
53ad0407
DS
238 grep -v "^+" test_err >err &&
239 test_i18ngrep "$GREPSTR" err
240}
241
242test_expect_success 'verify bad signature' '
243 corrupt_midx_and_verify 0 "\00" $objdir \
244 "multi-pack-index signature"
245'
246
3c5e65ca 247HASH_LEN=$(test_oid rawsz)
cc6af73c 248NUM_OBJECTS=74
53ad0407
DS
249MIDX_BYTE_VERSION=4
250MIDX_BYTE_OID_VERSION=5
251MIDX_BYTE_CHUNK_COUNT=6
d3f8e211
DS
252MIDX_HEADER_SIZE=12
253MIDX_BYTE_CHUNK_ID=$MIDX_HEADER_SIZE
254MIDX_BYTE_CHUNK_OFFSET=$(($MIDX_HEADER_SIZE + 4))
8e72a3c3
DS
255MIDX_NUM_CHUNKS=5
256MIDX_CHUNK_LOOKUP_WIDTH=12
257MIDX_OFFSET_PACKNAMES=$(($MIDX_HEADER_SIZE + \
258 $MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
259MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2))
3c5e65ca 260MIDX_OFFSET_OID_FANOUT=$(($MIDX_OFFSET_PACKNAMES + $(test_oid packnameoff)))
2f23d3f3 261MIDX_OID_FANOUT_WIDTH=4
3c5e65ca 262MIDX_BYTE_OID_FANOUT_ORDER=$((MIDX_OFFSET_OID_FANOUT + 250 * $MIDX_OID_FANOUT_WIDTH + $(test_oid fanoutoff)))
55c5648d
DS
263MIDX_OFFSET_OID_LOOKUP=$(($MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
264MIDX_BYTE_OID_LOOKUP=$(($MIDX_OFFSET_OID_LOOKUP + 16 * $HASH_LEN))
cc6af73c
DS
265MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
266MIDX_OFFSET_WIDTH=8
267MIDX_BYTE_PACK_INT_ID=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 2))
268MIDX_BYTE_OFFSET=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 6))
53ad0407
DS
269
270test_expect_success 'verify bad version' '
271 corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
272 "multi-pack-index version"
273'
274
275test_expect_success 'verify bad OID version' '
276 corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\02" $objdir \
277 "hash version"
278'
279
280test_expect_success 'verify truncated chunk count' '
281 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\01" $objdir \
282 "missing required"
283'
284
285test_expect_success 'verify extended chunk count' '
286 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\07" $objdir \
287 "terminating multi-pack-index chunk id appears earlier than expected"
288'
289
d3f8e211
DS
290test_expect_success 'verify missing required chunk' '
291 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_ID "\01" $objdir \
292 "missing required"
293'
294
295test_expect_success 'verify invalid chunk offset' '
296 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_OFFSET "\01" $objdir \
297 "invalid chunk offset (too large)"
298'
299
8e72a3c3
DS
300test_expect_success 'verify packnames out of order' '
301 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \
302 "pack names out of order"
303'
304
d4bf1d88
DS
305test_expect_success 'verify packnames out of order' '
306 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "a" $objdir \
307 "failed to load pack"
308'
309
2f23d3f3
DS
310test_expect_success 'verify oid fanout out of order' '
311 corrupt_midx_and_verify $MIDX_BYTE_OID_FANOUT_ORDER "\01" $objdir \
312 "oid fanout out of order"
313'
314
55c5648d
DS
315test_expect_success 'verify oid lookup out of order' '
316 corrupt_midx_and_verify $MIDX_BYTE_OID_LOOKUP "\00" $objdir \
317 "oid lookup out of order"
318'
319
cc6af73c
DS
320test_expect_success 'verify incorrect pack-int-id' '
321 corrupt_midx_and_verify $MIDX_BYTE_PACK_INT_ID "\07" $objdir \
322 "bad pack-int-id"
323'
324
325test_expect_success 'verify incorrect offset' '
235d3cdd 326 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
cc6af73c
DS
327 "incorrect object offset"
328'
329
66ec0390 330test_expect_success 'git-fsck incorrect offset' '
235d3cdd 331 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
66ec0390
DS
332 "incorrect object offset" \
333 "git -c core.multipackindex=true fsck"
334'
335
680cba2c
WB
336test_expect_success 'repack progress off for redirected stderr' '
337 git multi-pack-index --object-dir=$objdir repack 2>err &&
338 test_line_count = 0 err
339'
340
341test_expect_success 'repack force progress on for stderr' '
342 git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
343 test_file_not_empty err
344'
345
346test_expect_success 'repack with the --no-progress option' '
347 git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
348 test_line_count = 0 err
349'
350
525e18c0
DS
351test_expect_success 'repack removes multi-pack-index' '
352 test_path_is_file $objdir/pack/multi-pack-index &&
0465a505 353 GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
525e18c0
DS
354 test_path_is_missing $objdir/pack/multi-pack-index
355'
356
357compare_results_with_midx "after repack"
358
e9ab2ed7
DS
359test_expect_success 'multi-pack-index and pack-bitmap' '
360 git -c repack.writeBitmaps=true repack -ad &&
361 git multi-pack-index write &&
362 git rev-list --test-bitmap HEAD
363'
364
29e2016b
DS
365test_expect_success 'multi-pack-index and alternates' '
366 git init --bare alt.git &&
367 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
368 echo content1 >file1 &&
369 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
370 git cat-file blob $altblob &&
371 git rev-list --all
372'
373
374compare_results_with_midx "with alternate (local midx)"
375
376test_expect_success 'multi-pack-index in an alternate' '
6a22d521
DS
377 mv .git/objects/pack/* alt.git/objects/pack &&
378 test_commit add_local_objects &&
379 git repack --local &&
380 git multi-pack-index write &&
381 midx_read_expect 1 3 4 $objdir &&
382 git reset --hard HEAD~1 &&
383 rm -f .git/objects/pack/*
29e2016b
DS
384'
385
386compare_results_with_midx "with alternate (remote midx)"
387
662148c4
DS
388# usage: corrupt_data <file> <pos> [<data>]
389corrupt_data () {
390 file=$1
391 pos=$2
392 data="${3:-\0}"
393 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
394}
395
396# Force 64-bit offsets by manipulating the idx file.
397# This makes the IDX file _incorrect_ so be careful to clean up after!
398test_expect_success 'force some 64-bit offsets with pack-objects' '
399 mkdir objects64 &&
400 mkdir objects64/pack &&
401 for i in $(test_seq 1 11)
402 do
403 generate_objects 11
404 done &&
405 commit_and_list_objects &&
406 pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
407 idx64=objects64/pack/test-64-$pack64.idx &&
408 chmod u+w $idx64 &&
3c5e65ca 409 corrupt_data $idx64 $(test_oid idxoff) "\02" &&
662148c4
DS
410 midx64=$(git multi-pack-index --object-dir=objects64 write) &&
411 midx_read_expect 1 63 5 objects64 " large-offsets"
2c381335
DS
412'
413
56ee7ff1
DS
414test_expect_success 'verify multi-pack-index with 64-bit offsets' '
415 git multi-pack-index verify --object-dir=objects64
416'
417
cc6af73c
DS
418NUM_OBJECTS=63
419MIDX_OFFSET_OID_FANOUT=$((MIDX_OFFSET_PACKNAMES + 54))
420MIDX_OFFSET_OID_LOOKUP=$((MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
421MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
422MIDX_OFFSET_LARGE_OFFSETS=$(($MIDX_OFFSET_OBJECT_OFFSETS + $NUM_OBJECTS * $MIDX_OFFSET_WIDTH))
423MIDX_BYTE_LARGE_OFFSET=$(($MIDX_OFFSET_LARGE_OFFSETS + 3))
424
425test_expect_success 'verify incorrect 64-bit offset' '
426 corrupt_midx_and_verify $MIDX_BYTE_LARGE_OFFSET "\07" objects64 \
427 "incorrect object offset"
428'
429
cff97116
DS
430test_expect_success 'setup expire tests' '
431 mkdir dup &&
432 (
433 cd dup &&
434 git init &&
435 test-tool genrandom "data" 4096 >large_file.txt &&
436 git update-index --add large_file.txt &&
437 for i in $(test_seq 1 20)
438 do
439 test_commit $i
440 done &&
441 git branch A HEAD &&
442 git branch B HEAD~8 &&
443 git branch C HEAD~13 &&
444 git branch D HEAD~16 &&
445 git branch E HEAD~18 &&
446 git pack-objects --revs .git/objects/pack/pack-A <<-EOF &&
447 refs/heads/A
448 ^refs/heads/B
449 EOF
450 git pack-objects --revs .git/objects/pack/pack-B <<-EOF &&
451 refs/heads/B
452 ^refs/heads/C
453 EOF
454 git pack-objects --revs .git/objects/pack/pack-C <<-EOF &&
455 refs/heads/C
456 ^refs/heads/D
457 EOF
458 git pack-objects --revs .git/objects/pack/pack-D <<-EOF &&
459 refs/heads/D
460 ^refs/heads/E
461 EOF
462 git pack-objects --revs .git/objects/pack/pack-E <<-EOF &&
463 refs/heads/E
464 EOF
2af890bb
DS
465 git multi-pack-index write &&
466 cp -r .git/objects/pack .git/objects/pack-backup
cff97116
DS
467 )
468'
469
470test_expect_success 'expire does not remove any packs' '
471 (
472 cd dup &&
473 ls .git/objects/pack >expect &&
474 git multi-pack-index expire &&
475 ls .git/objects/pack >actual &&
476 test_cmp expect actual
477 )
478'
479
680cba2c
WB
480test_expect_success 'expire progress off for redirected stderr' '
481 (
482 cd dup &&
483 git multi-pack-index expire 2>err &&
484 test_line_count = 0 err
485 )
486'
487
488test_expect_success 'expire force progress on for stderr' '
489 (
490 cd dup &&
491 git multi-pack-index --progress expire 2>err &&
492 test_file_not_empty err
493 )
494'
495
496test_expect_success 'expire with the --no-progress option' '
497 (
498 cd dup &&
499 git multi-pack-index --no-progress expire 2>err &&
500 test_line_count = 0 err
501 )
502'
503
19575c7c
DS
504test_expect_success 'expire removes unreferenced packs' '
505 (
506 cd dup &&
507 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
508 refs/heads/A
509 ^refs/heads/C
510 EOF
511 git multi-pack-index write &&
512 ls .git/objects/pack | grep -v -e pack-[AB] >expect &&
513 git multi-pack-index expire &&
514 ls .git/objects/pack >actual &&
515 test_cmp expect actual &&
516 ls .git/objects/pack/ | grep idx >expect-idx &&
517 test-tool read-midx .git/objects | grep idx >actual-midx &&
518 test_cmp expect-idx actual-midx &&
519 git multi-pack-index verify &&
520 git fsck
521 )
522'
523
2af890bb
DS
524test_expect_success 'repack with minimum size does not alter existing packs' '
525 (
526 cd dup &&
527 rm -rf .git/objects/pack &&
528 mv .git/objects/pack-backup .git/objects/pack &&
e892a568
DS
529 test-tool chmtime =-5 .git/objects/pack/pack-D* &&
530 test-tool chmtime =-4 .git/objects/pack/pack-C* &&
531 test-tool chmtime =-3 .git/objects/pack/pack-B* &&
532 test-tool chmtime =-2 .git/objects/pack/pack-A* &&
2af890bb 533 ls .git/objects/pack >expect &&
3612c233 534 MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
2af890bb
DS
535 git multi-pack-index repack --batch-size=$MINSIZE &&
536 ls .git/objects/pack >actual &&
537 test_cmp expect actual
538 )
539'
540
3ce4ca0a
DS
541test_expect_success 'repack respects repack.packKeptObjects=false' '
542 test_when_finished rm -f dup/.git/objects/pack/*keep &&
543 (
544 cd dup &&
545 ls .git/objects/pack/*idx >idx-list &&
546 test_line_count = 5 idx-list &&
547 ls .git/objects/pack/*.pack | sed "s/\.pack/.keep/" >keep-list &&
548 test_line_count = 5 keep-list &&
549 for keep in $(cat keep-list)
550 do
551 touch $keep || return 1
552 done &&
553 git multi-pack-index repack --batch-size=0 &&
554 ls .git/objects/pack/*idx >idx-list &&
555 test_line_count = 5 idx-list &&
556 test-tool read-midx .git/objects | grep idx >midx-list &&
557 test_line_count = 5 midx-list &&
558 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) &&
559 BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) &&
560 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
561 ls .git/objects/pack/*idx >idx-list &&
562 test_line_count = 5 idx-list &&
563 test-tool read-midx .git/objects | grep idx >midx-list &&
564 test_line_count = 5 midx-list
565 )
566'
567
ce1e4a10
DS
568test_expect_success 'repack creates a new pack' '
569 (
570 cd dup &&
571 ls .git/objects/pack/*idx >idx-list &&
572 test_line_count = 5 idx-list &&
3612c233 573 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
ce1e4a10
DS
574 BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
575 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
576 ls .git/objects/pack/*idx >idx-list &&
577 test_line_count = 6 idx-list &&
578 test-tool read-midx .git/objects | grep idx >midx-list &&
579 test_line_count = 6 midx-list
580 )
581'
582
583test_expect_success 'expire removes repacked packs' '
584 (
585 cd dup &&
586 ls -al .git/objects/pack/*pack &&
587 ls -S .git/objects/pack/*pack | head -n 4 >expect &&
588 git multi-pack-index expire &&
589 ls -S .git/objects/pack/*pack >actual &&
590 test_cmp expect actual &&
591 test-tool read-midx .git/objects | grep idx >midx-list &&
592 test_line_count = 4 midx-list
593 )
594'
595
d2743315
DS
596test_expect_success 'expire works when adding new packs' '
597 (
598 cd dup &&
599 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
600 refs/heads/A
601 ^refs/heads/B
602 EOF
603 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
604 refs/heads/B
605 ^refs/heads/C
606 EOF
607 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
608 refs/heads/C
609 ^refs/heads/D
610 EOF
611 git multi-pack-index write &&
612 git pack-objects --revs .git/objects/pack/a-pack <<-EOF &&
613 refs/heads/D
614 ^refs/heads/E
615 EOF
616 git multi-pack-index write &&
617 git pack-objects --revs .git/objects/pack/z-pack <<-EOF &&
618 refs/heads/E
619 EOF
620 git multi-pack-index expire &&
621 ls .git/objects/pack/ | grep idx >expect &&
622 test-tool read-midx .git/objects | grep idx >actual &&
623 test_cmp expect actual &&
624 git multi-pack-index verify
625 )
626'
627
10bfa3f7
DS
628test_expect_success 'expire respects .keep files' '
629 (
630 cd dup &&
631 git pack-objects --revs .git/objects/pack/pack-all <<-EOF &&
632 refs/heads/A
633 EOF
634 git multi-pack-index write &&
635 PACKA=$(ls .git/objects/pack/a-pack*\.pack | sed s/\.pack\$//) &&
636 touch $PACKA.keep &&
637 git multi-pack-index expire &&
638 ls -S .git/objects/pack/a-pack* | grep $PACKA >a-pack-files &&
639 test_line_count = 3 a-pack-files &&
640 test-tool read-midx .git/objects | grep idx >midx-list &&
641 test_line_count = 2 midx-list
642 )
643'
644
b526d8cb
DS
645test_expect_success 'repack --batch-size=0 repacks everything' '
646 (
647 cd dup &&
648 rm .git/objects/pack/*.keep &&
649 ls .git/objects/pack/*idx >idx-list &&
650 test_line_count = 2 idx-list &&
651 git multi-pack-index repack --batch-size=0 &&
652 ls .git/objects/pack/*idx >idx-list &&
653 test_line_count = 3 idx-list &&
654 test-tool read-midx .git/objects | grep idx >midx-list &&
655 test_line_count = 3 midx-list &&
656 git multi-pack-index expire &&
657 ls -al .git/objects/pack/*idx >idx-list &&
658 test_line_count = 1 idx-list &&
659 git multi-pack-index repack --batch-size=0 &&
660 ls -al .git/objects/pack/*idx >new-idx-list &&
661 test_cmp idx-list new-idx-list
662 )
663'
10bfa3f7 664
a3407730 665test_done