3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git-pack-object
18 dd if=/dev/zero bs=4k count=1 | tr "\\0" $i >$i &&
19 git-update-index --add $i || return 1
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` && {
26 git-ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
28 git-diff-tree --root -p $commit &&
31 t=`git-cat-file -t $object` &&
32 git-cat-file $t $object || return 1
37 'pack without delta' \
38 'packname_1=$(git-pack-objects --window=0 test-1 <obj-list)'
44 'unpack without delta' \
45 "GIT_OBJECT_DIRECTORY=.git2/objects &&
46 export GIT_OBJECT_DIRECTORY &&
48 git-unpack-objects -n <test-1-${packname_1}.pack &&
49 git-unpack-objects <test-1-${packname_1}.pack"
51 unset GIT_OBJECT_DIRECTORY
55 'check unpack without delta' \
56 '(cd ../.git && find objects -type f -print) |
59 cmp $path ../.git/$path || {
69 packname_2=$(git-pack-objects test-2 <obj-list)'
76 'GIT_OBJECT_DIRECTORY=.git2/objects &&
77 export GIT_OBJECT_DIRECTORY &&
79 git-unpack-objects -n <test-2-${packname_2}.pack &&
80 git-unpack-objects <test-2-${packname_2}.pack'
82 unset GIT_OBJECT_DIRECTORY
85 'check unpack with delta' \
86 '(cd ../.git && find objects -type f -print) |
89 cmp $path ../.git/$path || {
100 'use packed objects' \
101 'GIT_OBJECT_DIRECTORY=.git2/objects &&
102 export GIT_OBJECT_DIRECTORY &&
104 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
105 git-diff-tree --root -p $commit &&
108 t=`git-cat-file -t $object` &&
109 git-cat-file $t $object || return 1
115 test_expect_success \
116 'use packed deltified objects' \
117 'GIT_OBJECT_DIRECTORY=.git2/objects &&
118 export GIT_OBJECT_DIRECTORY &&
119 rm -f .git2/objects/pack/test-?.idx &&
120 cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
121 git-diff-tree --root -p $commit &&
124 t=`git-cat-file -t $object` &&
125 git-cat-file $t $object || return 1
130 unset GIT_OBJECT_DIRECTORY
132 test_expect_success \
134 'git-verify-pack test-1-${packname_1}.idx test-2-${packname_2}.idx'
136 test_expect_success \
137 'corrupt a pack and see if verify catches' \
138 'cp test-1-${packname_1}.idx test-3.idx &&
139 cp test-2-${packname_2}.pack test-3.pack &&
140 if git-verify-pack test-3.idx
146 cp test-1-${packname_1}.pack test-3.pack &&
147 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
148 if git-verify-pack test-3.idx
154 cp test-1-${packname_1}.pack test-3.pack &&
155 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
156 if git-verify-pack test-3.idx
161 : TYPE/SIZE byte of the first packed object data &&
162 cp test-1-${packname_1}.pack test-3.pack &&
163 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
164 if git-verify-pack test-3.idx
169 : sum of the index file itself &&
170 l=`wc -c <test-3.idx` &&
171 l=`expr "$l" - 20` &&
172 cp test-1-${packname_1}.pack test-3.pack &&
173 dd if=/dev/zero of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
174 if git-verify-pack test-3.pack
181 test_expect_success \
182 'build pack index for an existing pack' \
183 'cp test-1-${packname_1}.pack test-3.pack &&
184 git-index-pack -o tmp.idx test-3.pack &&
185 cmp tmp.idx test-1-${packname_1}.idx &&
187 git-index-pack test-3.pack &&
188 cmp test-3.idx test-1-${packname_1}.idx &&
190 cp test-2-${packname_2}.pack test-3.pack &&
191 git-index-pack -o tmp.idx test-2-${packname_2}.pack &&
192 cmp tmp.idx test-2-${packname_2}.idx &&
194 git-index-pack test-3.pack &&
195 cmp test-3.idx test-2-${packname_2}.idx &&