Merge branch 'jc/relnotes-v0-extension-update' into master
[git/raj.git] / t / t1050-large.sh
blob6a56d1ca246f3437ab7f8dfd77d9eef9fe4b4144
1 #!/bin/sh
2 # Copyright (c) 2011, Google Inc.
4 test_description='adding and checking out large blobs'
6 . ./test-lib.sh
8 # This should be moved to test-lib.sh together with the
9 # copy in t0021 after both topics have graduated to 'master'.
10 file_size () {
11 test-tool path-utils file-size "$1"
14 test_expect_success setup '
15 test_oid_init &&
16 # clone does not allow us to pass core.bigfilethreshold to
17 # new repos, so set core.bigfilethreshold globally
18 git config --global core.bigfilethreshold 200k &&
19 printf "%2000000s" X >large1 &&
20 cp large1 large2 &&
21 cp large1 large3 &&
22 printf "%2500000s" Y >huge &&
23 GIT_ALLOC_LIMIT=1500k &&
24 export GIT_ALLOC_LIMIT
27 # add a large file with different settings
28 while read expect config
30 test_expect_success "add with $config" '
31 test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
32 git $config add large1 &&
33 sz=$(file_size .git/objects/pack/pack-*.pack) &&
34 case "$expect" in
35 small) test "$sz" -le 100000 ;;
36 large) test "$sz" -ge 100000 ;;
37 esac
39 done <<\EOF
40 large -c core.compression=0
41 small -c core.compression=9
42 large -c core.compression=0 -c pack.compression=0
43 large -c core.compression=9 -c pack.compression=0
44 small -c core.compression=0 -c pack.compression=9
45 small -c core.compression=9 -c pack.compression=9
46 large -c pack.compression=0
47 small -c pack.compression=9
48 EOF
50 test_expect_success 'add a large file or two' '
51 git add large1 huge large2 &&
52 # make sure we got a single packfile and no loose objects
53 bad= count=0 idx= &&
54 for p in .git/objects/pack/pack-*.pack
56 count=$(( $count + 1 ))
57 if test_path_is_file "$p" &&
58 idx=${p%.pack}.idx && test_path_is_file "$idx"
59 then
60 continue
62 bad=t
63 done &&
64 test -z "$bad" &&
65 test $count = 1 &&
66 cnt=$(git show-index <"$idx" | wc -l) &&
67 test $cnt = 2 &&
68 for l in .git/objects/$OIDPATH_REGEX
70 test_path_is_file "$l" || continue
71 bad=t
72 done &&
73 test -z "$bad" &&
75 # attempt to add another copy of the same
76 git add large3 &&
77 bad= count=0 &&
78 for p in .git/objects/pack/pack-*.pack
80 count=$(( $count + 1 ))
81 if test_path_is_file "$p" &&
82 idx=${p%.pack}.idx && test_path_is_file "$idx"
83 then
84 continue
86 bad=t
87 done &&
88 test -z "$bad" &&
89 test $count = 1
92 test_expect_success 'checkout a large file' '
93 large1=$(git rev-parse :large1) &&
94 git update-index --add --cacheinfo 100644 $large1 another &&
95 git checkout another &&
96 test_cmp large1 another
99 test_expect_success 'packsize limit' '
100 test_create_repo mid &&
102 cd mid &&
103 git config core.bigfilethreshold 64k &&
104 git config pack.packsizelimit 256k &&
106 # mid1 and mid2 will fit within 256k limit but
107 # appending mid3 will bust the limit and will
108 # result in a separate packfile.
109 test-tool genrandom "a" $(( 66 * 1024 )) >mid1 &&
110 test-tool genrandom "b" $(( 80 * 1024 )) >mid2 &&
111 test-tool genrandom "c" $(( 128 * 1024 )) >mid3 &&
112 git add mid1 mid2 mid3 &&
114 count=0 &&
115 for pi in .git/objects/pack/pack-*.idx
117 test_path_is_file "$pi" && count=$(( $count + 1 ))
118 done &&
119 test $count = 2 &&
122 git hash-object --stdin <mid1 &&
123 git hash-object --stdin <mid2 &&
124 git hash-object --stdin <mid3
126 sort >expect &&
128 for pi in .git/objects/pack/pack-*.idx
130 git show-index <"$pi"
131 done |
132 sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" |
133 sort >actual &&
135 test_cmp expect actual
139 test_expect_success 'diff --raw' '
140 git commit -q -m initial &&
141 echo modified >>large1 &&
142 git add large1 &&
143 git commit -q -m modified &&
144 git diff --raw HEAD^
147 test_expect_success 'diff --stat' '
148 git diff --stat HEAD^ HEAD
151 test_expect_success 'diff' '
152 git diff HEAD^ HEAD >actual &&
153 grep "Binary files.*differ" actual
156 test_expect_success 'diff --cached' '
157 git diff --cached HEAD^ >actual &&
158 grep "Binary files.*differ" actual
161 test_expect_success 'hash-object' '
162 git hash-object large1
165 test_expect_success 'cat-file a large file' '
166 git cat-file blob :large1 >/dev/null
169 test_expect_success 'cat-file a large file from a tag' '
170 git tag -m largefile largefiletag :large1 &&
171 git cat-file blob largefiletag >/dev/null
174 test_expect_success 'git-show a large file' '
175 git show :large1 >/dev/null
179 test_expect_success 'index-pack' '
180 git clone file://"$(pwd)"/.git foo &&
181 GIT_DIR=non-existent git index-pack --object-format=$(test_oid algo) \
182 --strict --verify foo/.git/objects/pack/*.pack
185 test_expect_success 'repack' '
186 git repack -ad
189 test_expect_success 'pack-objects with large loose object' '
190 SHA1=$(git hash-object huge) &&
191 test_create_repo loose &&
192 echo $SHA1 | git pack-objects --stdout |
193 GIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects &&
194 echo $SHA1 | GIT_DIR=loose/.git git pack-objects pack &&
195 test_create_repo packed &&
196 mv pack-* packed/.git/objects/pack &&
197 GIT_DIR=packed/.git git cat-file blob $SHA1 >actual &&
198 test_cmp huge actual
201 test_expect_success 'tar archiving' '
202 git archive --format=tar HEAD >/dev/null
205 test_expect_success 'zip archiving, store only' '
206 git archive --format=zip -0 HEAD >/dev/null
209 test_expect_success 'zip archiving, deflate' '
210 git archive --format=zip HEAD >/dev/null
213 test_expect_success 'fsck large blobs' '
214 git fsck 2>err &&
215 test_must_be_empty err
218 test_done