]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1050-large.sh
Merge branch 'ma/header-dup-cleanup'
[thirdparty/git.git] / t / t1050-large.sh
1 #!/bin/sh
2 # Copyright (c) 2011, Google Inc.
3
4 test_description='adding and checking out large blobs'
5
6 . ./test-lib.sh
7
8 test_expect_success setup '
9 # clone does not allow us to pass core.bigfilethreshold to
10 # new repos, so set core.bigfilethreshold globally
11 git config --global core.bigfilethreshold 200k &&
12 printf "%2000000s" X >large1 &&
13 cp large1 large2 &&
14 cp large1 large3 &&
15 printf "%2500000s" Y >huge &&
16 GIT_ALLOC_LIMIT=1500k &&
17 export GIT_ALLOC_LIMIT
18 '
19
20 test_expect_success 'enter "large" codepath, with small core.bigFileThreshold' '
21 test_when_finished "rm -rf repo" &&
22
23 git init --bare repo &&
24 echo large | git -C repo hash-object -w --stdin &&
25 git -C repo -c core.bigfilethreshold=4 fsck
26 '
27
28 # add a large file with different settings
29 while read expect config
30 do
31 test_expect_success "add with $config" '
32 test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
33 git $config add large1 &&
34 sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
35 case "$expect" in
36 small) test "$sz" -le 100000 ;;
37 large) test "$sz" -ge 100000 ;;
38 esac
39 '
40 done <<\EOF
41 large -c core.compression=0
42 small -c core.compression=9
43 large -c core.compression=0 -c pack.compression=0
44 large -c core.compression=9 -c pack.compression=0
45 small -c core.compression=0 -c pack.compression=9
46 small -c core.compression=9 -c pack.compression=9
47 large -c pack.compression=0
48 small -c pack.compression=9
49 EOF
50
51 test_expect_success 'add a large file or two' '
52 git add large1 huge large2 &&
53 # make sure we got a single packfile and no loose objects
54 count=0 idx= &&
55 for p in .git/objects/pack/pack-*.pack
56 do
57 count=$(( $count + 1 )) &&
58 test_path_is_file "$p" &&
59 idx=${p%.pack}.idx &&
60 test_path_is_file "$idx" || return 1
61 done &&
62 test $count = 1 &&
63 cnt=$(git show-index <"$idx" | wc -l) &&
64 test $cnt = 2 &&
65 for l in .git/objects/$OIDPATH_REGEX
66 do
67 test_path_is_missing "$l" || return 1
68 done &&
69
70 # attempt to add another copy of the same
71 git add large3 &&
72 bad= count=0 &&
73 for p in .git/objects/pack/pack-*.pack
74 do
75 count=$(( $count + 1 )) &&
76 test_path_is_file "$p" &&
77 idx=${p%.pack}.idx &&
78 test_path_is_file "$idx" || return 1
79 done &&
80 test $count = 1
81 '
82
83 test_expect_success 'checkout a large file' '
84 large1=$(git rev-parse :large1) &&
85 git update-index --add --cacheinfo 100644 $large1 another &&
86 git checkout another &&
87 test_cmp large1 another
88 '
89
90 test_expect_success 'packsize limit' '
91 test_create_repo mid &&
92 (
93 cd mid &&
94 git config core.bigfilethreshold 64k &&
95 git config pack.packsizelimit 256k &&
96
97 # mid1 and mid2 will fit within 256k limit but
98 # appending mid3 will bust the limit and will
99 # result in a separate packfile.
100 test-tool genrandom "a" $(( 66 * 1024 )) >mid1 &&
101 test-tool genrandom "b" $(( 80 * 1024 )) >mid2 &&
102 test-tool genrandom "c" $(( 128 * 1024 )) >mid3 &&
103 git add mid1 mid2 mid3 &&
104
105 count=0 &&
106 for pi in .git/objects/pack/pack-*.idx
107 do
108 test_path_is_file "$pi" && count=$(( $count + 1 )) || return 1
109 done &&
110 test $count = 2 &&
111
112 (
113 git hash-object --stdin <mid1 &&
114 git hash-object --stdin <mid2 &&
115 git hash-object --stdin <mid3
116 ) |
117 sort >expect &&
118
119 for pi in .git/objects/pack/pack-*.idx
120 do
121 git show-index <"$pi" || return 1
122 done |
123 sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" |
124 sort >actual &&
125
126 test_cmp expect actual
127 )
128 '
129
130 test_expect_success 'diff --raw' '
131 git commit -q -m initial &&
132 echo modified >>large1 &&
133 git add large1 &&
134 git commit -q -m modified &&
135 git diff --raw HEAD^
136 '
137
138 test_expect_success 'diff --stat' '
139 git diff --stat HEAD^ HEAD
140 '
141
142 test_expect_success 'diff' '
143 git diff HEAD^ HEAD >actual &&
144 grep "Binary files.*differ" actual
145 '
146
147 test_expect_success 'diff --cached' '
148 git diff --cached HEAD^ >actual &&
149 grep "Binary files.*differ" actual
150 '
151
152 test_expect_success 'hash-object' '
153 git hash-object large1
154 '
155
156 test_expect_success 'cat-file a large file' '
157 git cat-file blob :large1 >/dev/null
158 '
159
160 test_expect_success 'cat-file a large file from a tag' '
161 git tag -m largefile largefiletag :large1 &&
162 git cat-file blob largefiletag >/dev/null
163 '
164
165 test_expect_success 'git-show a large file' '
166 git show :large1 >/dev/null
167
168 '
169
170 test_expect_success 'index-pack' '
171 git clone file://"$(pwd)"/.git foo &&
172 GIT_DIR=non-existent git index-pack --object-format=$(test_oid algo) \
173 --strict --verify foo/.git/objects/pack/*.pack
174 '
175
176 test_expect_success 'repack' '
177 git repack -ad
178 '
179
180 test_expect_success 'pack-objects with large loose object' '
181 SHA1=$(git hash-object huge) &&
182 test_create_repo loose &&
183 echo $SHA1 | git pack-objects --stdout |
184 GIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects &&
185 echo $SHA1 | GIT_DIR=loose/.git git pack-objects pack &&
186 test_create_repo packed &&
187 mv pack-* packed/.git/objects/pack &&
188 GIT_DIR=packed/.git git cat-file blob $SHA1 >actual &&
189 test_cmp huge actual
190 '
191
192 test_expect_success 'tar archiving' '
193 git archive --format=tar HEAD >/dev/null
194 '
195
196 test_expect_success 'zip archiving, store only' '
197 git archive --format=zip -0 HEAD >/dev/null
198 '
199
200 test_expect_success 'zip archiving, deflate' '
201 git archive --format=zip HEAD >/dev/null
202 '
203
204 test_expect_success 'fsck large blobs' '
205 git fsck 2>err &&
206 test_must_be_empty err
207 '
208
209 test_done