t/helper: refactor to not use `struct reftable_table`

The `struct reftable_table` interface in our "reftable" test helper gets used such that we can easily print either a single table, or a merged stack. This generic interface is about to go away. Prepare the code for this change by using merged tables instead. When printing the stack we've already got one. When using a single table, we can create a merged table from it to adapt. This removes the last user of the generic interface. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 22, 2024 at 08:35 UTC 89191232b8459a4061438a88bdb14d914802a579
1 file changed +18 -15
t/helper/test-reftable.c
+18 -15
@@ -3,7 +3,6 @@
3 #include "hex.h"
4 #include "reftable/system.h"
5 #include "reftable/reftable-error.h"
6 -#include "reftable/reftable-generic.h"
6 #include "reftable/reftable-merged.h"
7 #include "reftable/reftable-reader.h"
8 #include "reftable/reftable-stack.h"
@@ -33,7 +32,7 @@ static void print_help(void)
32 "\n");
33 }
34
36 -static int dump_table(struct reftable_table *tab)
35 +static int dump_table(struct reftable_merged_table *mt)
36 {
37 struct reftable_iterator it = { NULL };
38 struct reftable_ref_record ref = { NULL };
@@ -41,13 +40,12 @@ static int dump_table(struct reftable_table *tab)
40 const struct git_hash_algo *algop;
41 int err;
42
44 - reftable_table_init_ref_iter(tab, &it);
45 -
43 + reftable_merged_table_init_ref_iterator(mt, &it);
44 err = reftable_iterator_seek_ref(&it, "");
45 if (err < 0)
46 return err;
47
50 - algop = &hash_algos[hash_algo_by_id(reftable_table_hash_id(tab))];
48 + algop = &hash_algos[hash_algo_by_id(reftable_merged_table_hash_id(mt))];
49
50 while (1) {
51 err = reftable_iterator_next_ref(&it, &ref);
@@ -77,8 +75,7 @@ static int dump_table(struct reftable_table *tab)
75 reftable_iterator_destroy(&it);
76 reftable_ref_record_release(&ref);
77
80 - reftable_table_init_log_iter(tab, &it);
81 -
78 + reftable_merged_table_init_log_iterator(mt, &it);
79 err = reftable_iterator_seek_log(&it, "");
80 if (err < 0)
81 return err;
@@ -118,15 +115,13 @@ static int dump_stack(const char *stackdir, uint32_t hash_id)
115 struct reftable_stack *stack = NULL;
116 struct reftable_write_options opts = { .hash_id = hash_id };
117 struct reftable_merged_table *merged = NULL;
121 - struct reftable_table table = { NULL };
118
119 int err = reftable_new_stack(&stack, stackdir, &opts);
120 if (err < 0)
121 goto done;
122
123 merged = reftable_stack_merged_table(stack);
128 - reftable_table_from_merged_table(&table, merged);
129 - err = dump_table(&table);
124 + err = dump_table(merged);
125 done:
126 if (stack)
127 reftable_stack_destroy(stack);
@@ -135,10 +130,12 @@ done:
130
131 static int dump_reftable(const char *tablename)
132 {
138 - struct reftable_block_source src = { NULL };
139 - int err = reftable_block_source_from_file(&src, tablename);
133 + struct reftable_block_source src = { 0 };
134 + struct reftable_merged_table *mt = NULL;
135 struct reftable_reader *r = NULL;
141 - struct reftable_table tab = { NULL };
136 + int err;
137 +
138 + err = reftable_block_source_from_file(&src, tablename);
139 if (err < 0)
140 goto done;
141
@@ -146,9 +143,15 @@ static int dump_reftable(const char *tablename)
143 if (err < 0)
144 goto done;
145
149 - reftable_table_from_reader(&tab, r);
150 - err = dump_table(&tab);
146 + err = reftable_merged_table_new(&mt, &r, 1,
147 + reftable_reader_hash_id(r));
148 + if (err < 0)
149 + goto done;
150 +
151 + err = dump_table(mt);
152 +
153 done:
154 + reftable_merged_table_free(mt);
155 reftable_reader_free(r);
156 return err;
157 }