t/helper: inline `reftable_stack_print_directory()`

Move `reftable_stack_print_directory()` into the "dump-reftable" helper. This follows the same reasoning as the preceding commit. Note that this requires us to remove the tests for this functionality in `reftable/stack_test.c`. The test does not really add much anyway, because all it verifies is that we do not crash or run into an error, and it specifically doesn't check the outputted data. Also, as the code is now part of the test helper, it doesn't make much sense to have a unit test for it in the first place. 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 ca74ef6ffb7388d862379d5016282340aff1f68b
4 files changed +22 -31
reftable/reftable-stack.h
-3
@@ -140,7 +140,4 @@ struct reftable_compaction_stats {
140 struct reftable_compaction_stats *
141 reftable_stack_compaction_stats(struct reftable_stack *st);
142
143 -/* print the entire stack represented by the directory */
144 -int reftable_stack_print_directory(const char *stackdir, uint32_t hash_id);
145 -
143 #endif
reftable/stack.c
-20
@@ -1603,23 +1603,3 @@ done:
1603 reftable_addition_destroy(add);
1604 return err;
1605 }
1606 -
1607 -int reftable_stack_print_directory(const char *stackdir, uint32_t hash_id)
1608 -{
1609 - struct reftable_stack *stack = NULL;
1610 - struct reftable_write_options opts = { .hash_id = hash_id };
1611 - struct reftable_merged_table *merged = NULL;
1612 - struct reftable_table table = { NULL };
1613 -
1614 - int err = reftable_new_stack(&stack, stackdir, &opts);
1615 - if (err < 0)
1616 - goto done;
1617 -
1618 - merged = reftable_stack_merged_table(stack);
1619 - reftable_table_from_merged_table(&table, merged);
1620 - err = reftable_table_print(&table);
1621 -done:
1622 - if (stack)
1623 - reftable_stack_destroy(stack);
1624 - return err;
1625 -}
reftable/stack_test.c
-7
@@ -179,13 +179,6 @@ static void test_reftable_stack_add_one(void)
179 EXPECT(0 == strcmp("master", dest.value.symref));
180 EXPECT(st->readers_len > 0);
181
182 - printf("testing print functionality:\n");
183 - err = reftable_stack_print_directory(dir, GIT_SHA1_FORMAT_ID);
184 - EXPECT_ERR(err);
185 -
186 - err = reftable_stack_print_directory(dir, GIT_SHA256_FORMAT_ID);
187 - EXPECT(err == REFTABLE_FORMAT_ERROR);
188 -
182 #ifndef GIT_WINDOWS_NATIVE
183 strbuf_addstr(&scratch, dir);
184 strbuf_addstr(&scratch, "/tables.list");
t/helper/test-reftable.c
+22 -1
@@ -1,6 +1,7 @@
1 #include "reftable/system.h"
2 #include "reftable/reftable-error.h"
3 #include "reftable/reftable-generic.h"
4 +#include "reftable/reftable-merged.h"
5 #include "reftable/reftable-reader.h"
6 #include "reftable/reftable-stack.h"
7 #include "reftable/reftable-tests.h"
@@ -29,6 +30,26 @@ static void print_help(void)
30 "\n");
31 }
32
33 +static int dump_stack(const char *stackdir, uint32_t hash_id)
34 +{
35 + struct reftable_stack *stack = NULL;
36 + struct reftable_write_options opts = { .hash_id = hash_id };
37 + struct reftable_merged_table *merged = NULL;
38 + struct reftable_table table = { NULL };
39 +
40 + int err = reftable_new_stack(&stack, stackdir, &opts);
41 + if (err < 0)
42 + goto done;
43 +
44 + merged = reftable_stack_merged_table(stack);
45 + reftable_table_from_merged_table(&table, merged);
46 + err = reftable_table_print(&table);
47 +done:
48 + if (stack)
49 + reftable_stack_destroy(stack);
50 + return err;
51 +}
52 +
53 static int dump_reftable(const char *tablename)
54 {
55 struct reftable_block_source src = { NULL };
@@ -87,7 +108,7 @@ int cmd__dump_reftable(int argc, const char **argv)
108 } else if (opt_dump_table) {
109 err = dump_reftable(arg);
110 } else if (opt_dump_stack) {
90 - err = reftable_stack_print_directory(arg, opt_hash_id);
111 + err = dump_stack(arg, opt_hash_id);
112 }
113
114 if (err < 0) {