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