reftable/stack: expose option to disable auto-compaction

The reftable stack already has a variable to configure whether or not to run auto-compaction, but it is inaccessible to users of the library. There exist use cases where a caller may want to have more control over auto-compaction. Move the `disable_auto_compact` option into `reftable_write_options` to allow external callers to disable auto-compaction. This will be used in a subsequent commit. Signed-off-by: Justin Tobler <jltobler@gmail.com> Acked-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Apr 8, 2024 at 16:16 UTC bc91330cecfdc9a00a486923126a969fee6ace36
4 files changed +10 -7
reftable/reftable-writer.h
+3
@@ -46,6 +46,9 @@ struct reftable_write_options {
46 * is a single line, and add '\n' if missing.
47 */
48 unsigned exact_log_message : 1;
49 +
50 + /* boolean: Prevent auto-compaction of tables. */
51 + unsigned disable_auto_compact : 1;
52 };
53
54 /* reftable_block_stats holds statistics for a single block type */
reftable/stack.c
+1 -1
@@ -680,7 +680,7 @@ int reftable_addition_commit(struct reftable_addition *add)
680 if (err)
681 goto done;
682
683 - if (!add->stack->disable_auto_compact) {
683 + if (!add->stack->config.disable_auto_compact) {
684 /*
685 * Auto-compact the stack to keep the number of tables in
686 * control. It is possible that a concurrent writer is already
reftable/stack.h
-1
@@ -19,7 +19,6 @@ struct reftable_stack {
19 int list_fd;
20
21 char *reftable_dir;
22 - int disable_auto_compact;
22
23 struct reftable_write_options config;
24
reftable/stack_test.c
+6 -5
@@ -315,7 +315,7 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
315 * we can ensure that we indeed honor this setting and have
316 * better control over when exactly auto compaction runs.
317 */
318 - st->disable_auto_compact = i != n;
318 + st->config.disable_auto_compact = i != n;
319
320 err = reftable_stack_new_addition(&add, st);
321 EXPECT_ERR(err);
@@ -487,6 +487,7 @@ static void test_reftable_stack_add(void)
487 struct reftable_write_options cfg = {
488 .exact_log_message = 1,
489 .default_permissions = 0660,
490 + .disable_auto_compact = 1,
491 };
492 struct reftable_stack *st = NULL;
493 char *dir = get_tmp_dir(__LINE__);
@@ -498,7 +499,6 @@ static void test_reftable_stack_add(void)
499
500 err = reftable_new_stack(&st, dir, cfg);
501 EXPECT_ERR(err);
501 - st->disable_auto_compact = 1;
502
503 for (i = 0; i < N; i++) {
504 char buf[256];
@@ -925,7 +925,9 @@ static void test_empty_add(void)
925
926 static void test_reftable_stack_auto_compaction(void)
927 {
928 - struct reftable_write_options cfg = { 0 };
928 + struct reftable_write_options cfg = {
929 + .disable_auto_compact = 1,
930 + };
931 struct reftable_stack *st = NULL;
932 char *dir = get_tmp_dir(__LINE__);
933
@@ -935,7 +937,6 @@ static void test_reftable_stack_auto_compaction(void)
937 err = reftable_new_stack(&st, dir, cfg);
938 EXPECT_ERR(err);
939
938 - st->disable_auto_compact = 1; /* call manually below for coverage. */
940 for (i = 0; i < N; i++) {
941 char name[100];
942 struct reftable_ref_record ref = {
@@ -984,7 +985,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
985 * we can ensure that we indeed honor this setting and have
986 * better control over when exactly auto compaction runs.
987 */
987 - st->disable_auto_compact = i != n;
988 + st->config.disable_auto_compact = i != n;
989
990 strbuf_reset(&refname);
991 strbuf_addf(&refname, "branch-%04d", i);