summaryrefslogtreecommitdiffstats
path: root/t/t0613-reftable-write-options.sh
blob: e2708e11d5b941cf707d3c22466e4cc6957d0302 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/sh

test_description='reftable write options'

GIT_TEST_DEFAULT_REF_FORMAT=reftable
export GIT_TEST_DEFAULT_REF_FORMAT
# Disable auto-compaction for all tests as we explicitly control repacking of
# refs.
GIT_TEST_REFTABLE_AUTOCOMPACTION=false
export GIT_TEST_REFTABLE_AUTOCOMPACTION
# Block sizes depend on the hash function, so we force SHA1 here.
GIT_TEST_DEFAULT_HASH=sha1
export GIT_TEST_DEFAULT_HASH
# Block sizes also depend on the actual refs we write, so we force "master" to
# be the default initial branch name.
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME

. ./test-lib.sh

test_expect_success 'default write options' '
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit initial &&
		git pack-refs &&
		cat >expect <<-EOF &&
		header:
		  block_size: 4096
		ref:
		  - length: 129
		    restarts: 2
		log:
		  - length: 262
		    restarts: 2
		EOF
		test-tool dump-reftable -b .git/reftable/*.ref >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'disabled reflog writes no log blocks' '
	test_config_global core.logAllRefUpdates false &&
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit initial &&
		git pack-refs &&
		cat >expect <<-EOF &&
		header:
		  block_size: 4096
		ref:
		  - length: 129
		    restarts: 2
		EOF
		test-tool dump-reftable -b .git/reftable/*.ref >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'many refs results in multiple blocks' '
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit initial &&
		for i in $(test_seq 200)
		do
			printf "update refs/heads/branch-%d HEAD\n" "$i" ||
			return 1
		done >input &&
		git update-ref --stdin <input &&
		git pack-refs &&

		cat >expect <<-EOF &&
		header:
		  block_size: 4096
		ref:
		  - length: 4049
		    restarts: 11
		  - length: 1136
		    restarts: 3
		log:
		  - length: 4041
		    restarts: 4
		  - length: 4015
		    restarts: 3
		  - length: 4014
		    restarts: 3
		  - length: 4012
		    restarts: 3
		  - length: 3289
		    restarts: 3
		EOF
		test-tool dump-reftable -b .git/reftable/*.ref >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'tiny block size leads to error' '
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit initial &&
		cat >expect <<-EOF &&
		error: unable to compact stack: entry too large
		EOF
		test_must_fail git -c reftable.blockSize=50 pack-refs 2>err &&
		test_cmp expect err
	)
'

test_expect_success 'small block size leads to multiple ref blocks' '
	test_config_global core.logAllRefUpdates false &&
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit A &&
		test_commit B &&
		git -c reftable.blockSize=100 pack-refs &&

		cat >expect <<-EOF &&
		header:
		  block_size: 100
		ref:
		  - length: 53
		    restarts: 1
		  - length: 74
		    restarts: 1
		  - length: 38
		    restarts: 1
		EOF
		test-tool dump-reftable -b .git/reftable/*.ref >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'small block size fails with large reflog message' '
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit A &&
		perl -e "print \"a\" x 500" >logmsg &&
		cat >expect <<-EOF &&
		fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
		EOF
		test_must_fail git -c reftable.blockSize=100 \
			update-ref -m "$(cat logmsg)" refs/heads/logme HEAD 2>err &&
		test_cmp expect err
	)
'

test_expect_success 'block size exceeding maximum supported size' '
	test_config_global core.logAllRefUpdates false &&
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit A &&
		test_commit B &&
		cat >expect <<-EOF &&
		fatal: reftable block size cannot exceed 16MB
		EOF
		test_must_fail git -c reftable.blockSize=16777216 pack-refs 2>err &&
		test_cmp expect err
	)
'

test_expect_success 'restart interval at every single record' '
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit initial &&
		for i in $(test_seq 10)
		do
			printf "update refs/heads/branch-%d HEAD\n" "$i" ||
			return 1
		done >input &&
		git update-ref --stdin <input &&
		git -c reftable.restartInterval=1 pack-refs &&

		cat >expect <<-EOF &&
		header:
		  block_size: 4096
		ref:
		  - length: 566
		    restarts: 13
		log:
		  - length: 1393
		    restarts: 12
		EOF
		test-tool dump-reftable -b .git/reftable/*.ref >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'restart interval exceeding maximum supported interval' '
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit initial &&
		cat >expect <<-EOF &&
		fatal: reftable block size cannot exceed 65535
		EOF
		test_must_fail git -c reftable.restartInterval=65536 pack-refs 2>err &&
		test_cmp expect err
	)
'

test_expect_success 'object index gets written by default with ref index' '
	test_config_global core.logAllRefUpdates false &&
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit initial &&
		for i in $(test_seq 5)
		do
			printf "update refs/heads/branch-%d HEAD\n" "$i" ||
			return 1
		done >input &&
		git update-ref --stdin <input &&
		git -c reftable.blockSize=100 pack-refs &&

		cat >expect <<-EOF &&
		header:
		  block_size: 100
		ref:
		  - length: 53
		    restarts: 1
		  - length: 95
		    restarts: 1
		  - length: 71
		    restarts: 1
		  - length: 80
		    restarts: 1
		obj:
		  - length: 11
		    restarts: 1
		EOF
		test-tool dump-reftable -b .git/reftable/*.ref >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'object index can be disabled' '
	test_config_global core.logAllRefUpdates false &&
	test_when_finished "rm -rf repo" &&
	git init repo &&
	(
		cd repo &&
		test_commit initial &&
		for i in $(test_seq 5)
		do
			printf "update refs/heads/branch-%d HEAD\n" "$i" ||
			return 1
		done >input &&
		git update-ref --stdin <input &&
		git -c reftable.blockSize=100 -c reftable.indexObjects=false pack-refs &&

		cat >expect <<-EOF &&
		header:
		  block_size: 100
		ref:
		  - length: 53
		    restarts: 1
		  - length: 95
		    restarts: 1
		  - length: 71
		    restarts: 1
		  - length: 80
		    restarts: 1
		EOF
		test-tool dump-reftable -b .git/reftable/*.ref >actual &&
		test_cmp expect actual
	)
'

test_done