Skip to content

Commit ca74ef6

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22f519a commit ca74ef6

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

reftable/reftable-stack.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,4 @@ struct reftable_compaction_stats {
140140
struct reftable_compaction_stats *
141141
reftable_stack_compaction_stats(struct reftable_stack *st);
142142

143-
/* print the entire stack represented by the directory */
144-
int reftable_stack_print_directory(const char *stackdir, uint32_t hash_id);
145-
146143
#endif

reftable/stack.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,23 +1603,3 @@ int reftable_stack_clean(struct reftable_stack *st)
16031603
reftable_addition_destroy(add);
16041604
return err;
16051605
}
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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,6 @@ static void test_reftable_stack_add_one(void)
179179
EXPECT(0 == strcmp("master", dest.value.symref));
180180
EXPECT(st->readers_len > 0);
181181

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-
189182
#ifndef GIT_WINDOWS_NATIVE
190183
strbuf_addstr(&scratch, dir);
191184
strbuf_addstr(&scratch, "/tables.list");

t/helper/test-reftable.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "reftable/system.h"
22
#include "reftable/reftable-error.h"
33
#include "reftable/reftable-generic.h"
4+
#include "reftable/reftable-merged.h"
45
#include "reftable/reftable-reader.h"
56
#include "reftable/reftable-stack.h"
67
#include "reftable/reftable-tests.h"
@@ -29,6 +30,26 @@ static void print_help(void)
2930
"\n");
3031
}
3132

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+
3253
static int dump_reftable(const char *tablename)
3354
{
3455
struct reftable_block_source src = { NULL };
@@ -87,7 +108,7 @@ int cmd__dump_reftable(int argc, const char **argv)
87108
} else if (opt_dump_table) {
88109
err = dump_reftable(arg);
89110
} else if (opt_dump_stack) {
90-
err = reftable_stack_print_directory(arg, opt_hash_id);
111+
err = dump_stack(arg, opt_hash_id);
91112
}
92113

93114
if (err < 0) {

0 commit comments

Comments
 (0)