Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t0613-reftable-write-options.sh
blobb1c6c97524f16cb5ba15cf814ff8f959e4cb0c80
1 #!/bin/sh
3 test_description='reftable write options'
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 # Block sizes also depend on the actual refs we write, so we force "master" to
15 # be the default initial branch name.
16 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
17 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
19 TEST_PASSES_SANITIZE_LEAK=true
20 . ./test-lib.sh
22 test_expect_success 'default write options' '
23 test_when_finished "rm -rf repo" &&
24 git init repo &&
26 cd repo &&
27 test_commit initial &&
28 git pack-refs &&
29 cat >expect <<-EOF &&
30 header:
31 block_size: 4096
32 ref:
33 - length: 129
34 restarts: 2
35 log:
36 - length: 262
37 restarts: 2
38 EOF
39 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
40 test_cmp expect actual
44 test_expect_success 'disabled reflog writes no log blocks' '
45 test_config_global core.logAllRefUpdates false &&
46 test_when_finished "rm -rf repo" &&
47 git init repo &&
49 cd repo &&
50 test_commit initial &&
51 git pack-refs &&
52 cat >expect <<-EOF &&
53 header:
54 block_size: 4096
55 ref:
56 - length: 129
57 restarts: 2
58 EOF
59 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
60 test_cmp expect actual
64 test_expect_success 'many refs results in multiple blocks' '
65 test_when_finished "rm -rf repo" &&
66 git init repo &&
68 cd repo &&
69 test_commit initial &&
70 for i in $(test_seq 200)
72 printf "update refs/heads/branch-%d HEAD\n" "$i" ||
73 return 1
74 done >input &&
75 git update-ref --stdin <input &&
76 git pack-refs &&
78 cat >expect <<-EOF &&
79 header:
80 block_size: 4096
81 ref:
82 - length: 4049
83 restarts: 11
84 - length: 1136
85 restarts: 3
86 log:
87 - length: 4041
88 restarts: 4
89 - length: 4015
90 restarts: 3
91 - length: 4014
92 restarts: 3
93 - length: 4012
94 restarts: 3
95 - length: 3289
96 restarts: 3
97 EOF
98 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
99 test_cmp expect actual
103 test_expect_success 'tiny block size leads to error' '
104 test_when_finished "rm -rf repo" &&
105 git init repo &&
107 cd repo &&
108 test_commit initial &&
109 cat >expect <<-EOF &&
110 error: unable to compact stack: entry too large
112 test_must_fail git -c reftable.blockSize=50 pack-refs 2>err &&
113 test_cmp expect err
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 git init repo &&
122 cd repo &&
123 test_commit A &&
124 test_commit B &&
125 git -c reftable.blockSize=100 pack-refs &&
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
138 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
139 test_cmp expect actual
143 test_expect_success 'small block size fails with large reflog message' '
144 test_when_finished "rm -rf repo" &&
145 git init repo &&
147 cd repo &&
148 test_commit A &&
149 perl -e "print \"a\" x 500" >logmsg &&
150 cat >expect <<-EOF &&
151 fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
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
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 &&
164 cd repo &&
165 test_commit A &&
166 test_commit B &&
167 cat >expect <<-EOF &&
168 fatal: reftable block size cannot exceed 16MB
170 test_must_fail git -c reftable.blockSize=16777216 pack-refs 2>err &&
171 test_cmp expect err
175 test_expect_success 'restart interval at every single record' '
176 test_when_finished "rm -rf repo" &&
177 git init repo &&
179 cd repo &&
180 test_commit initial &&
181 for i in $(test_seq 10)
183 printf "update refs/heads/branch-%d HEAD\n" "$i" ||
184 return 1
185 done >input &&
186 git update-ref --stdin <input &&
187 git -c reftable.restartInterval=1 pack-refs &&
189 cat >expect <<-EOF &&
190 header:
191 block_size: 4096
192 ref:
193 - length: 566
194 restarts: 13
195 log:
196 - length: 1393
197 restarts: 12
199 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
200 test_cmp expect actual
204 test_expect_success 'restart interval exceeding maximum supported interval' '
205 test_when_finished "rm -rf repo" &&
206 git init repo &&
208 cd repo &&
209 test_commit initial &&
210 cat >expect <<-EOF &&
211 fatal: reftable block size cannot exceed 65535
213 test_must_fail git -c reftable.restartInterval=65536 pack-refs 2>err &&
214 test_cmp expect err
218 test_expect_success 'object index gets written by default with ref index' '
219 test_config_global core.logAllRefUpdates false &&
220 test_when_finished "rm -rf repo" &&
221 git init repo &&
223 cd repo &&
224 test_commit initial &&
225 for i in $(test_seq 5)
227 printf "update refs/heads/branch-%d HEAD\n" "$i" ||
228 return 1
229 done >input &&
230 git update-ref --stdin <input &&
231 git -c reftable.blockSize=100 pack-refs &&
233 cat >expect <<-EOF &&
234 header:
235 block_size: 100
236 ref:
237 - length: 53
238 restarts: 1
239 - length: 95
240 restarts: 1
241 - length: 71
242 restarts: 1
243 - length: 80
244 restarts: 1
245 obj:
246 - length: 11
247 restarts: 1
249 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
250 test_cmp expect actual
254 test_expect_success 'object index can be disabled' '
255 test_config_global core.logAllRefUpdates false &&
256 test_when_finished "rm -rf repo" &&
257 git init repo &&
259 cd repo &&
260 test_commit initial &&
261 for i in $(test_seq 5)
263 printf "update refs/heads/branch-%d HEAD\n" "$i" ||
264 return 1
265 done >input &&
266 git update-ref --stdin <input &&
267 git -c reftable.blockSize=100 -c reftable.indexObjects=false pack-refs &&
269 cat >expect <<-EOF &&
270 header:
271 block_size: 100
272 ref:
273 - length: 53
274 restarts: 1
275 - length: 95
276 restarts: 1
277 - length: 71
278 restarts: 1
279 - length: 80
280 restarts: 1
282 test-tool dump-reftable -b .git/reftable/*.ref >actual &&
283 test_cmp expect actual
287 test_done