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