Raw
1 #!/bin/sh
2
3 test_description='reftable write options'
4
5 GIT_TEST_DEFAULT_REF_FORMAT=reftable
6 export GIT_TEST_DEFAULT_REF_FORMAT
7 # Disable auto-compaction for all tests as we explicitly control repacking of
8 # refs.
9 GIT_TEST_REFTABLE_AUTOCOMPACTION=false
10 export GIT_TEST_REFTABLE_AUTOCOMPACTION
11 # Block sizes depend on the hash function, so we force SHA1 here.
12 GIT_TEST_DEFAULT_HASH=sha1
13 export GIT_TEST_DEFAULT_HASH
14
15 . ./test-lib.sh
16
17 # Block sizes depend on the actual refs we write, so, for tests
18 # that check block size, we force the initial branch name to be "master".
19 init_repo () {
20 git init --initial-branch master repo
21 }
22
23 test_expect_success 'default write options' '
24 test_when_finished "rm -rf repo" &&
25 init_repo &&
26 (
27 cd repo &&
28 test_commit initial &&
29 git pack-refs &&
30 cat >expect <<-EOF &&
31 header:
32 block_size: 4096
33 ref:
34 - length: 129
35 restarts: 2
36 log:
37 - length: 262
38 restarts: 2
39 EOF
40 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
41 test_cmp expect actual
42 )
43 '
44
45 test_expect_success 'disabled reflog writes no log blocks' '
46 test_config_global core.logAllRefUpdates false &&
47 test_when_finished "rm -rf repo" &&
48 init_repo &&
49 (
50 cd repo &&
51 test_commit initial &&
52 git pack-refs &&
53 cat >expect <<-EOF &&
54 header:
55 block_size: 4096
56 ref:
57 - length: 129
58 restarts: 2
59 EOF
60 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
61 test_cmp expect actual
62 )
63 '
64
65 test_expect_success 'many refs results in multiple blocks' '
66 test_when_finished "rm -rf repo" &&
67 init_repo &&
68 (
69 cd repo &&
70 test_commit initial &&
71 test_seq -f "update refs/heads/branch-%d HEAD" 200 |
72 git update-ref --stdin &&
73 git pack-refs &&
74
75 cat >expect <<-EOF &&
76 header:
77 block_size: 4096
78 ref:
79 - length: 4049
80 restarts: 11
81 - length: 1136
82 restarts: 3
83 log:
84 - length: 4041
85 restarts: 4
86 - length: 4015
87 restarts: 3
88 - length: 4014
89 restarts: 3
90 - length: 4012
91 restarts: 3
92 - length: 3289
93 restarts: 3
94 idx:
95 - length: 103
96 restarts: 1
97 EOF
98 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
99 test_cmp expect actual
100 )
101 '
102
103 test_expect_success 'tiny block size leads to error' '
104 test_when_finished "rm -rf repo" &&
105 git init repo &&
106 (
107 cd repo &&
108 test_commit initial &&
109 cat >expect <<-EOF &&
110 error: unable to compact stack: entry too large
111 EOF
112 test_must_fail git -c reftable.blockSize=50 pack-refs 2>err &&
113 test_cmp expect err
114 )
115 '
116
117 test_expect_success 'small block size leads to multiple ref blocks' '
118 test_config_global core.logAllRefUpdates false &&
119 test_when_finished "rm -rf repo" &&
120 init_repo &&
121 (
122 cd repo &&
123 test_commit A &&
124 test_commit B &&
125 git -c reftable.blockSize=100 pack-refs &&
126
127 cat >expect <<-EOF &&
128 header:
129 block_size: 100
130 ref:
131 - length: 53
132 restarts: 1
133 - length: 74
134 restarts: 1
135 - length: 38
136 restarts: 1
137 EOF
138 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
139 test_cmp expect actual
140 )
141 '
142
143 test_expect_success 'small block size fails with large reflog message' '
144 test_when_finished "rm -rf repo" &&
145 git init repo &&
146 (
147 cd repo &&
148 test_commit A &&
149 test-tool genzeros 500 | tr "\000" "a" >logmsg &&
150 cat >expect <<-EOF &&
151 fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
152 EOF
153 test_must_fail git -c reftable.blockSize=100 \
154 update-ref -m "$(cat logmsg)" refs/heads/logme HEAD 2>err &&
155 test_cmp expect err
156 )
157 '
158
159 test_expect_success 'block size exceeding maximum supported size' '
160 test_config_global core.logAllRefUpdates false &&
161 test_when_finished "rm -rf repo" &&
162 git init repo &&
163 (
164 cd repo &&
165 test_commit A &&
166 test_commit B &&
167 cat >expect <<-EOF &&
168 fatal: reftable block size cannot exceed 16MB
169 EOF
170 test_must_fail git -c reftable.blockSize=16777216 pack-refs 2>err &&
171 test_cmp expect err
172 )
173 '
174
175 test_expect_success 'restart interval at every single record' '
176 test_when_finished "rm -rf repo" &&
177 init_repo &&
178 (
179 cd repo &&
180 test_commit initial &&
181 test_seq -f "update refs/heads/branch-%d HEAD" 10 |
182 git update-ref --stdin &&
183 git -c reftable.restartInterval=1 pack-refs &&
184
185 cat >expect <<-EOF &&
186 header:
187 block_size: 4096
188 ref:
189 - length: 566
190 restarts: 13
191 log:
192 - length: 1393
193 restarts: 12
194 EOF
195 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
196 test_cmp expect actual
197 )
198 '
199
200 test_expect_success 'restart interval exceeding maximum supported interval' '
201 test_when_finished "rm -rf repo" &&
202 git init repo &&
203 (
204 cd repo &&
205 test_commit initial &&
206 cat >expect <<-EOF &&
207 fatal: reftable block size cannot exceed 65535
208 EOF
209 test_must_fail git -c reftable.restartInterval=65536 pack-refs 2>err &&
210 test_cmp expect err
211 )
212 '
213
214 test_expect_success 'object index gets written by default with ref index' '
215 test_config_global core.logAllRefUpdates false &&
216 test_when_finished "rm -rf repo" &&
217 init_repo &&
218 (
219 cd repo &&
220 test_commit initial &&
221 test_seq -f "update refs/heads/branch-%d HEAD" 5 |
222 git update-ref --stdin &&
223 git -c reftable.blockSize=100 pack-refs &&
224
225 cat >expect <<-EOF &&
226 header:
227 block_size: 100
228 ref:
229 - length: 53
230 restarts: 1
231 - length: 95
232 restarts: 1
233 - length: 71
234 restarts: 1
235 - length: 80
236 restarts: 1
237 idx:
238 - length: 55
239 restarts: 2
240 obj:
241 - length: 11
242 restarts: 1
243 EOF
244 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
245 test_cmp expect actual
246 )
247 '
248
249 test_expect_success 'object index can be disabled' '
250 test_config_global core.logAllRefUpdates false &&
251 test_when_finished "rm -rf repo" &&
252 init_repo &&
253 (
254 cd repo &&
255 test_commit initial &&
256 test_seq -f "update refs/heads/branch-%d HEAD" 5 |
257 git update-ref --stdin &&
258 git -c reftable.blockSize=100 -c reftable.indexObjects=false pack-refs &&
259
260 cat >expect <<-EOF &&
261 header:
262 block_size: 100
263 ref:
264 - length: 53
265 restarts: 1
266 - length: 95
267 restarts: 1
268 - length: 71
269 restarts: 1
270 - length: 80
271 restarts: 1
272 idx:
273 - length: 55
274 restarts: 2
275 EOF
276 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
277 test_cmp expect actual
278 )
279 '
280
281 test_done