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