]>
Commit | Line | Data |
---|---|---|
8ee378a0 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
3604e7c5 | 6 | test_description='git pack-object |
8ee378a0 JH |
7 | |
8 | ' | |
9 | . ./test-lib.sh | |
10 | ||
d6cd9ac9 | 11 | TRASH=$(pwd) |
8ee378a0 JH |
12 | |
13 | test_expect_success \ | |
14 | 'setup' \ | |
a48fcd83 | 15 | 'rm -f .git/index* && |
94221d22 JK |
16 | perl -e "print \"a\" x 4096;" > a && |
17 | perl -e "print \"b\" x 4096;" > b && | |
18 | perl -e "print \"c\" x 4096;" > c && | |
07cf0f24 NP |
19 | test-genrandom "seed a" 2097152 > a_big && |
20 | test-genrandom "seed b" 2097152 > b_big && | |
21 | git update-index --add a a_big b b_big c && | |
5be60078 | 22 | cat c >d && echo foo >>d && git update-index --add d && |
d6cd9ac9 EP |
23 | tree=$(git write-tree) && |
24 | commit=$(git commit-tree $tree </dev/null) && { | |
8ee378a0 | 25 | echo $tree && |
1f688557 | 26 | echo $commit && |
5be60078 | 27 | git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/" |
1f688557 | 28 | } >obj-list && { |
5be60078 | 29 | git diff-tree --root -p $commit && |
1f688557 JH |
30 | while read object |
31 | do | |
d6cd9ac9 | 32 | t=$(git cat-file -t $object) && |
5be60078 | 33 | git cat-file $t $object || return 1 |
1f688557 JH |
34 | done <obj-list |
35 | } >expect' | |
8ee378a0 JH |
36 | |
37 | test_expect_success \ | |
38 | 'pack without delta' \ | |
5be60078 | 39 | 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)' |
8ee378a0 | 40 | |
3a2ec52e NTND |
41 | test_expect_success \ |
42 | 'pack-objects with bogus arguments' \ | |
43 | 'test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list' | |
44 | ||
8ee378a0 JH |
45 | rm -fr .git2 |
46 | mkdir .git2 | |
47 | ||
48 | test_expect_success \ | |
49 | 'unpack without delta' \ | |
a61eea6a | 50 | "GIT_OBJECT_DIRECTORY=.git2/objects && |
8ee378a0 | 51 | export GIT_OBJECT_DIRECTORY && |
5be60078 JH |
52 | git init && |
53 | git unpack-objects -n <test-1-${packname_1}.pack && | |
54 | git unpack-objects <test-1-${packname_1}.pack" | |
8ee378a0 JH |
55 | |
56 | unset GIT_OBJECT_DIRECTORY | |
f07a5241 | 57 | cd "$TRASH/.git2" |
8ee378a0 JH |
58 | |
59 | test_expect_success \ | |
60 | 'check unpack without delta' \ | |
61 | '(cd ../.git && find objects -type f -print) | | |
62 | while read path | |
63 | do | |
64 | cmp $path ../.git/$path || { | |
65 | echo $path differs. | |
4d9d62fa | 66 | return 1 |
8ee378a0 JH |
67 | } |
68 | done' | |
f07a5241 | 69 | cd "$TRASH" |
8ee378a0 JH |
70 | |
71 | test_expect_success \ | |
ac527b0b | 72 | 'pack with REF_DELTA' \ |
8ee378a0 | 73 | 'pwd && |
5be60078 | 74 | packname_2=$(git pack-objects test-2 <obj-list)' |
8ee378a0 JH |
75 | |
76 | rm -fr .git2 | |
77 | mkdir .git2 | |
78 | ||
79 | test_expect_success \ | |
ac527b0b | 80 | 'unpack with REF_DELTA' \ |
8ee378a0 JH |
81 | 'GIT_OBJECT_DIRECTORY=.git2/objects && |
82 | export GIT_OBJECT_DIRECTORY && | |
5be60078 JH |
83 | git init && |
84 | git unpack-objects -n <test-2-${packname_2}.pack && | |
85 | git unpack-objects <test-2-${packname_2}.pack' | |
8ee378a0 JH |
86 | |
87 | unset GIT_OBJECT_DIRECTORY | |
f07a5241 | 88 | cd "$TRASH/.git2" |
8ee378a0 | 89 | test_expect_success \ |
ac527b0b | 90 | 'check unpack with REF_DELTA' \ |
8ee378a0 JH |
91 | '(cd ../.git && find objects -type f -print) | |
92 | while read path | |
93 | do | |
94 | cmp $path ../.git/$path || { | |
95 | echo $path differs. | |
4d9d62fa | 96 | return 1 |
8ee378a0 JH |
97 | } |
98 | done' | |
f07a5241 | 99 | cd "$TRASH" |
8ee378a0 | 100 | |
ac527b0b NP |
101 | test_expect_success \ |
102 | 'pack with OFS_DELTA' \ | |
103 | 'pwd && | |
5be60078 | 104 | packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)' |
ac527b0b NP |
105 | |
106 | rm -fr .git2 | |
107 | mkdir .git2 | |
108 | ||
109 | test_expect_success \ | |
110 | 'unpack with OFS_DELTA' \ | |
111 | 'GIT_OBJECT_DIRECTORY=.git2/objects && | |
112 | export GIT_OBJECT_DIRECTORY && | |
5be60078 JH |
113 | git init && |
114 | git unpack-objects -n <test-3-${packname_3}.pack && | |
115 | git unpack-objects <test-3-${packname_3}.pack' | |
ac527b0b NP |
116 | |
117 | unset GIT_OBJECT_DIRECTORY | |
118 | cd "$TRASH/.git2" | |
119 | test_expect_success \ | |
120 | 'check unpack with OFS_DELTA' \ | |
121 | '(cd ../.git && find objects -type f -print) | | |
122 | while read path | |
123 | do | |
124 | cmp $path ../.git/$path || { | |
125 | echo $path differs. | |
126 | return 1 | |
127 | } | |
128 | done' | |
129 | cd "$TRASH" | |
130 | ||
d93f7c18 | 131 | test_expect_success 'compare delta flavors' ' |
94221d22 | 132 | perl -e '\'' |
d93f7c18 AL |
133 | defined($_ = -s $_) or die for @ARGV; |
134 | exit 1 if $ARGV[0] <= $ARGV[1]; | |
135 | '\'' test-2-$packname_2.pack test-3-$packname_3.pack | |
136 | ' | |
ac527b0b | 137 | |
1f688557 JH |
138 | rm -fr .git2 |
139 | mkdir .git2 | |
140 | ||
141 | test_expect_success \ | |
142 | 'use packed objects' \ | |
143 | 'GIT_OBJECT_DIRECTORY=.git2/objects && | |
144 | export GIT_OBJECT_DIRECTORY && | |
5be60078 | 145 | git init && |
a61eea6a | 146 | cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && { |
5be60078 | 147 | git diff-tree --root -p $commit && |
1f688557 JH |
148 | while read object |
149 | do | |
d6cd9ac9 | 150 | t=$(git cat-file -t $object) && |
5be60078 | 151 | git cat-file $t $object || return 1 |
1f688557 JH |
152 | done <obj-list |
153 | } >current && | |
ce1a0473 | 154 | cmp expect current' |
1f688557 | 155 | |
1f688557 | 156 | test_expect_success \ |
ac527b0b | 157 | 'use packed deltified (REF_DELTA) objects' \ |
1f688557 JH |
158 | 'GIT_OBJECT_DIRECTORY=.git2/objects && |
159 | export GIT_OBJECT_DIRECTORY && | |
a5878961 | 160 | rm -f .git2/objects/pack/test-* && |
a61eea6a | 161 | cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && { |
5be60078 | 162 | git diff-tree --root -p $commit && |
1f688557 JH |
163 | while read object |
164 | do | |
d6cd9ac9 | 165 | t=$(git cat-file -t $object) && |
5be60078 | 166 | git cat-file $t $object || return 1 |
1f688557 JH |
167 | done <obj-list |
168 | } >current && | |
ce1a0473 | 169 | cmp expect current' |
1f688557 | 170 | |
ac527b0b NP |
171 | test_expect_success \ |
172 | 'use packed deltified (OFS_DELTA) objects' \ | |
173 | 'GIT_OBJECT_DIRECTORY=.git2/objects && | |
174 | export GIT_OBJECT_DIRECTORY && | |
a5878961 | 175 | rm -f .git2/objects/pack/test-* && |
ac527b0b | 176 | cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && { |
5be60078 | 177 | git diff-tree --root -p $commit && |
ac527b0b NP |
178 | while read object |
179 | do | |
d6cd9ac9 | 180 | t=$(git cat-file -t $object) && |
5be60078 | 181 | git cat-file $t $object || return 1 |
ac527b0b NP |
182 | done <obj-list |
183 | } >current && | |
ce1a0473 | 184 | cmp expect current' |
ac527b0b | 185 | |
f9253394 JH |
186 | unset GIT_OBJECT_DIRECTORY |
187 | ||
6e180cdc JH |
188 | test_expect_success 'survive missing objects/pack directory' ' |
189 | ( | |
190 | rm -fr missing-pack && | |
191 | mkdir missing-pack && | |
192 | cd missing-pack && | |
193 | git init && | |
194 | GOP=.git/objects/pack | |
195 | rm -fr $GOP && | |
196 | git index-pack --stdin --keep=test <../test-3-${packname_3}.pack && | |
197 | test -f $GOP/pack-${packname_3}.pack && | |
ce1a0473 | 198 | cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack && |
6e180cdc | 199 | test -f $GOP/pack-${packname_3}.idx && |
ce1a0473 | 200 | cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx && |
6e180cdc JH |
201 | test -f $GOP/pack-${packname_3}.keep |
202 | ) | |
203 | ' | |
204 | ||
f9253394 JH |
205 | test_expect_success \ |
206 | 'verify pack' \ | |
5be60078 | 207 | 'git verify-pack test-1-${packname_1}.idx \ |
ac527b0b NP |
208 | test-2-${packname_2}.idx \ |
209 | test-3-${packname_3}.idx' | |
f9253394 | 210 | |
4b480c67 NP |
211 | test_expect_success \ |
212 | 'verify pack -v' \ | |
213 | 'git verify-pack -v test-1-${packname_1}.idx \ | |
214 | test-2-${packname_2}.idx \ | |
215 | test-3-${packname_3}.idx' | |
216 | ||
f9253394 | 217 | test_expect_success \ |
63405283 | 218 | 'verify-pack catches mismatched .idx and .pack files' \ |
a5878961 JH |
219 | 'cat test-1-${packname_1}.idx >test-3.idx && |
220 | cat test-2-${packname_2}.pack >test-3.pack && | |
5be60078 | 221 | if git verify-pack test-3.idx |
f9253394 JH |
222 | then false |
223 | else :; | |
63405283 | 224 | fi' |
f9253394 | 225 | |
63405283 JS |
226 | test_expect_success \ |
227 | 'verify-pack catches a corrupted pack signature' \ | |
228 | 'cat test-1-${packname_1}.pack >test-3.pack && | |
b689ccf6 | 229 | echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 && |
5be60078 | 230 | if git verify-pack test-3.idx |
f9253394 JH |
231 | then false |
232 | else :; | |
63405283 | 233 | fi' |
f9253394 | 234 | |
63405283 JS |
235 | test_expect_success \ |
236 | 'verify-pack catches a corrupted pack version' \ | |
237 | 'cat test-1-${packname_1}.pack >test-3.pack && | |
b689ccf6 | 238 | echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 && |
5be60078 | 239 | if git verify-pack test-3.idx |
f9253394 JH |
240 | then false |
241 | else :; | |
63405283 | 242 | fi' |
f9253394 | 243 | |
63405283 JS |
244 | test_expect_success \ |
245 | 'verify-pack catches a corrupted type/size of the 1st packed object data' \ | |
246 | 'cat test-1-${packname_1}.pack >test-3.pack && | |
b689ccf6 | 247 | echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 && |
5be60078 | 248 | if git verify-pack test-3.idx |
f9253394 JH |
249 | then false |
250 | else :; | |
63405283 | 251 | fi' |
f9253394 | 252 | |
63405283 JS |
253 | test_expect_success \ |
254 | 'verify-pack catches a corrupted sum of the index file itself' \ | |
d6cd9ac9 EP |
255 | 'l=$(wc -c <test-3.idx) && |
256 | l=$(expr $l - 20) && | |
a5878961 | 257 | cat test-1-${packname_1}.pack >test-3.pack && |
b689ccf6 | 258 | printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l && |
5be60078 | 259 | if git verify-pack test-3.pack |
c5ced645 JH |
260 | then false |
261 | else :; | |
63405283 | 262 | fi' |
f9253394 | 263 | |
9cf6d335 SV |
264 | test_expect_success \ |
265 | 'build pack index for an existing pack' \ | |
a5878961 | 266 | 'cat test-1-${packname_1}.pack >test-3.pack && |
3604e7c5 | 267 | git index-pack -o tmp.idx test-3.pack && |
9cf6d335 SV |
268 | cmp tmp.idx test-1-${packname_1}.idx && |
269 | ||
3604e7c5 | 270 | git index-pack test-3.pack && |
9cf6d335 SV |
271 | cmp test-3.idx test-1-${packname_1}.idx && |
272 | ||
a5878961 | 273 | cat test-2-${packname_2}.pack >test-3.pack && |
3604e7c5 | 274 | git index-pack -o tmp.idx test-2-${packname_2}.pack && |
9cf6d335 SV |
275 | cmp tmp.idx test-2-${packname_2}.idx && |
276 | ||
3604e7c5 | 277 | git index-pack test-3.pack && |
9cf6d335 SV |
278 | cmp test-3.idx test-2-${packname_2}.idx && |
279 | ||
a5878961 | 280 | cat test-3-${packname_3}.pack >test-3.pack && |
3604e7c5 | 281 | git index-pack -o tmp.idx test-3-${packname_3}.pack && |
ac527b0b NP |
282 | cmp tmp.idx test-3-${packname_3}.idx && |
283 | ||
3604e7c5 | 284 | git index-pack test-3.pack && |
ac527b0b NP |
285 | cmp test-3.idx test-3-${packname_3}.idx && |
286 | ||
0e94242d JH |
287 | cat test-1-${packname_1}.pack >test-4.pack && |
288 | rm -f test-4.keep && | |
289 | git index-pack --keep=why test-4.pack && | |
290 | cmp test-1-${packname_1}.idx test-4.idx && | |
291 | test -f test-4.keep && | |
292 | ||
9cf6d335 SV |
293 | :' |
294 | ||
f2898cfa | 295 | test_expect_success 'unpacking with --strict' ' |
c0e809e5 | 296 | |
c0e809e5 JH |
297 | for j in a b c d e f g |
298 | do | |
299 | for i in 0 1 2 3 4 5 6 7 8 9 | |
300 | do | |
301 | o=$(echo $j$i | git hash-object -w --stdin) && | |
302 | echo "100644 $o 0 $j$i" | |
303 | done | |
304 | done >LIST && | |
305 | rm -f .git/index && | |
306 | git update-index --index-info <LIST && | |
307 | LIST=$(git write-tree) && | |
308 | rm -f .git/index && | |
309 | head -n 10 LIST | git update-index --index-info && | |
310 | LI=$(git write-tree) && | |
311 | rm -f .git/index && | |
312 | tail -n 10 LIST | git update-index --index-info && | |
313 | ST=$(git write-tree) && | |
314 | PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \ | |
315 | git pack-objects test-5 ) && | |
316 | PACK6=$( ( | |
317 | echo "$LIST" | |
318 | echo "$LI" | |
319 | echo "$ST" | |
320 | ) | git pack-objects test-6 ) && | |
321 | test_create_repo test-5 && | |
322 | ( | |
323 | cd test-5 && | |
324 | git unpack-objects --strict <../test-5-$PACK5.pack && | |
325 | git ls-tree -r $LIST && | |
326 | git ls-tree -r $LI && | |
327 | git ls-tree -r $ST | |
328 | ) && | |
329 | test_create_repo test-6 && | |
330 | ( | |
331 | # tree-only into empty repo -- many unreachables | |
332 | cd test-6 && | |
333 | test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack | |
334 | ) && | |
335 | ( | |
336 | # already populated -- no unreachables | |
337 | cd test-5 && | |
338 | git unpack-objects --strict <../test-6-$PACK6.pack | |
339 | ) | |
340 | ' | |
341 | ||
38a5739d MK |
342 | test_expect_success 'index-pack with --strict' ' |
343 | ||
344 | for j in a b c d e f g | |
345 | do | |
346 | for i in 0 1 2 3 4 5 6 7 8 9 | |
347 | do | |
348 | o=$(echo $j$i | git hash-object -w --stdin) && | |
349 | echo "100644 $o 0 $j$i" | |
350 | done | |
351 | done >LIST && | |
352 | rm -f .git/index && | |
353 | git update-index --index-info <LIST && | |
354 | LIST=$(git write-tree) && | |
355 | rm -f .git/index && | |
356 | head -n 10 LIST | git update-index --index-info && | |
357 | LI=$(git write-tree) && | |
358 | rm -f .git/index && | |
359 | tail -n 10 LIST | git update-index --index-info && | |
360 | ST=$(git write-tree) && | |
361 | PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \ | |
362 | git pack-objects test-5 ) && | |
363 | PACK6=$( ( | |
364 | echo "$LIST" | |
365 | echo "$LI" | |
366 | echo "$ST" | |
367 | ) | git pack-objects test-6 ) && | |
368 | test_create_repo test-7 && | |
369 | ( | |
370 | cd test-7 && | |
371 | git index-pack --strict --stdin <../test-5-$PACK5.pack && | |
372 | git ls-tree -r $LIST && | |
373 | git ls-tree -r $LI && | |
374 | git ls-tree -r $ST | |
375 | ) && | |
376 | test_create_repo test-8 && | |
377 | ( | |
378 | # tree-only into empty repo -- many unreachables | |
379 | cd test-8 && | |
380 | test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack | |
381 | ) && | |
382 | ( | |
383 | # already populated -- no unreachables | |
384 | cd test-7 && | |
385 | git index-pack --strict --stdin <../test-6-$PACK6.pack | |
386 | ) | |
387 | ' | |
388 | ||
2fca19fb | 389 | test_expect_success 'honor pack.packSizeLimit' ' |
07cf0f24 | 390 | git config pack.packSizeLimit 3m && |
2fca19fb | 391 | packname_10=$(git pack-objects test-10 <obj-list) && |
07cf0f24 | 392 | test 2 = $(ls test-10-*.pack | wc -l) |
2fca19fb NP |
393 | ' |
394 | ||
395 | test_expect_success 'verify resulting packs' ' | |
396 | git verify-pack test-10-*.pack | |
397 | ' | |
398 | ||
07cf0f24 NP |
399 | test_expect_success 'tolerate packsizelimit smaller than biggest object' ' |
400 | git config pack.packSizeLimit 1 && | |
2fca19fb | 401 | packname_11=$(git pack-objects test-11 <obj-list) && |
720c9f7b | 402 | test 5 = $(ls test-11-*.pack | wc -l) |
a1e4760f NP |
403 | ' |
404 | ||
2fca19fb NP |
405 | test_expect_success 'verify resulting packs' ' |
406 | git verify-pack test-11-*.pack | |
407 | ' | |
408 | ||
409 | # | |
410 | # WARNING! | |
411 | # | |
412 | # The following test is destructive. Please keep the next | |
413 | # two tests at the end of this file. | |
414 | # | |
415 | ||
416 | test_expect_success \ | |
417 | 'fake a SHA1 hash collision' \ | |
418 | 'test -f .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 && | |
419 | cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \ | |
420 | .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67' | |
421 | ||
422 | test_expect_success \ | |
423 | 'make sure index-pack detects the SHA1 collision' \ | |
424 | 'test_must_fail git index-pack -o bad.idx test-3.pack 2>msg && | |
9aa98efc | 425 | test_i18ngrep "SHA1 COLLISION FOUND" msg' |
2fca19fb | 426 | |
4614043c NTND |
427 | test_expect_success \ |
428 | 'make sure index-pack detects the SHA1 collision (large blobs)' \ | |
429 | 'test_must_fail git -c core.bigfilethreshold=1 index-pack -o bad.idx test-3.pack 2>msg && | |
9aa98efc | 430 | test_i18ngrep "SHA1 COLLISION FOUND" msg' |
4614043c | 431 | |
8ee378a0 | 432 | test_done |