Skip to content

Commit afbdbfa

Browse files
pks-tgitster
authored andcommitted
refs/reftable: allow disabling writing the object index
Besides the expected "ref" and "log" records, the reftable library also writes "obj" records. These are basically a reverse mapping of object IDs to their respective ref records so that it becomes efficient to figure out which references point to a specific object. The motivation for this data structure is the "uploadpack.allowTipSHA1InWant" config, which allows a client to fetch any object by its hash that has a ref pointing to it. This reverse index is not used by Git at all though, and the expectation is that most hosters nowadays use "uploadpack.allowAnySHA1InWant". It may thus be preferable for many users to disable writing these optional object indices altogether to safe some precious disk space. Add a new config "reftable.indexObjects" that allows the user to disable the object index altogether. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90db611 commit afbdbfa

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

Documentation/config/reftable.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ A maximum of `65535` restart points per block is supported.
3030
+
3131
The default value is to create restart points every 16 records. A value of `0`
3232
will use the default value.
33+
34+
reftable.indexObjects::
35+
Whether the reftable backend shall write object blocks. Object blocks
36+
are a reverse mapping of object ID to the references pointing to them.
37+
+
38+
The default value is `true`.

refs/reftable-backend.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ static int reftable_be_config(const char *var, const char *value,
245245
if (restart_interval > UINT16_MAX)
246246
die("reftable block size cannot exceed %u", (unsigned)UINT16_MAX);
247247
opts->restart_interval = restart_interval;
248+
} else if (!strcmp(var, "reftable.indexobjects")) {
249+
opts->skip_index_objects = !git_config_bool(var, value);
248250
}
249251

250252
return 0;

t/t0613-reftable-write-options.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,73 @@ test_expect_success 'restart interval exceeding maximum supported interval' '
214214
)
215215
'
216216

217+
test_expect_success 'object index gets written by default with ref index' '
218+
test_config_global core.logAllRefUpdates false &&
219+
test_when_finished "rm -rf repo" &&
220+
git init repo &&
221+
(
222+
cd repo &&
223+
test_commit initial &&
224+
for i in $(test_seq 5)
225+
do
226+
printf "update refs/heads/branch-%d HEAD\n" "$i" ||
227+
return 1
228+
done >input &&
229+
git update-ref --stdin <input &&
230+
git -c reftable.blockSize=100 pack-refs &&
231+
232+
cat >expect <<-EOF &&
233+
header:
234+
block_size: 100
235+
ref:
236+
- length: 53
237+
restarts: 1
238+
- length: 95
239+
restarts: 1
240+
- length: 71
241+
restarts: 1
242+
- length: 80
243+
restarts: 1
244+
obj:
245+
- length: 11
246+
restarts: 1
247+
EOF
248+
test-tool dump-reftable -b .git/reftable/*.ref >actual &&
249+
test_cmp expect actual
250+
)
251+
'
252+
253+
test_expect_success 'object index can be disabled' '
254+
test_config_global core.logAllRefUpdates false &&
255+
test_when_finished "rm -rf repo" &&
256+
git init repo &&
257+
(
258+
cd repo &&
259+
test_commit initial &&
260+
for i in $(test_seq 5)
261+
do
262+
printf "update refs/heads/branch-%d HEAD\n" "$i" ||
263+
return 1
264+
done >input &&
265+
git update-ref --stdin <input &&
266+
git -c reftable.blockSize=100 -c reftable.indexObjects=false pack-refs &&
267+
268+
cat >expect <<-EOF &&
269+
header:
270+
block_size: 100
271+
ref:
272+
- length: 53
273+
restarts: 1
274+
- length: 95
275+
restarts: 1
276+
- length: 71
277+
restarts: 1
278+
- length: 80
279+
restarts: 1
280+
EOF
281+
test-tool dump-reftable -b .git/reftable/*.ref >actual &&
282+
test_cmp expect actual
283+
)
284+
'
285+
217286
test_done

0 commit comments

Comments
 (0)