Skip to content

Commit 2b06b28

Browse files
pks-tgitster
authored andcommitted
t/helper: inline reftable_dump_main()
The printing functionality part of `reftable/dump.c` is really only used by our "dump-reftable" test helper. It is certainly not generic logic that is useful to anybody outside of Git, and the format it generates is quite specific. Still, parts of it are used in our test suite and the output may be useful to take a peek into reftable stacks, tables and blocks. So while it does not make sense to expose this as part of the reftable library, it does make sense to keep it around. Inline the `reftable_dump_main()` function into the "dump-reftable" test helper. This clarifies that its format is subject to change and not part of our public interface. Furthermore, this allows us to iterate on the implementation in subsequent patches. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 55c7ff4 commit 2b06b28

File tree

4 files changed

+60
-89
lines changed

4 files changed

+60
-89
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2680,7 +2680,6 @@ REFTABLE_OBJS += reftable/tree.o
26802680
REFTABLE_OBJS += reftable/writer.o
26812681

26822682
REFTABLE_TEST_OBJS += reftable/block_test.o
2683-
REFTABLE_TEST_OBJS += reftable/dump.o
26842683
REFTABLE_TEST_OBJS += reftable/pq_test.o
26852684
REFTABLE_TEST_OBJS += reftable/readwrite_test.o
26862685
REFTABLE_TEST_OBJS += reftable/stack_test.o

reftable/dump.c

Lines changed: 0 additions & 86 deletions
This file was deleted.

reftable/reftable-tests.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ int record_test_main(int argc, const char **argv);
1616
int readwrite_test_main(int argc, const char **argv);
1717
int stack_test_main(int argc, const char **argv);
1818
int tree_test_main(int argc, const char **argv);
19-
int reftable_dump_main(int argc, char *const *argv);
2019

2120
#endif

t/helper/test-reftable.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "reftable/system.h"
2+
#include "reftable/reftable-error.h"
3+
#include "reftable/reftable-reader.h"
4+
#include "reftable/reftable-stack.h"
25
#include "reftable/reftable-tests.h"
36
#include "test-tool.h"
47

@@ -13,7 +16,63 @@ int cmd__reftable(int argc, const char **argv)
1316
return 0;
1417
}
1518

19+
static void print_help(void)
20+
{
21+
printf("usage: dump [-st] arg\n\n"
22+
"options: \n"
23+
" -b dump blocks\n"
24+
" -t dump table\n"
25+
" -s dump stack\n"
26+
" -6 sha256 hash format\n"
27+
" -h this help\n"
28+
"\n");
29+
}
30+
1631
int cmd__dump_reftable(int argc, const char **argv)
1732
{
18-
return reftable_dump_main(argc, (char *const *)argv);
33+
int err = 0;
34+
int opt_dump_blocks = 0;
35+
int opt_dump_table = 0;
36+
int opt_dump_stack = 0;
37+
uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID;
38+
const char *arg = NULL, *argv0 = argv[0];
39+
40+
for (; argc > 1; argv++, argc--)
41+
if (*argv[1] != '-')
42+
break;
43+
else if (!strcmp("-b", argv[1]))
44+
opt_dump_blocks = 1;
45+
else if (!strcmp("-t", argv[1]))
46+
opt_dump_table = 1;
47+
else if (!strcmp("-6", argv[1]))
48+
opt_hash_id = GIT_SHA256_FORMAT_ID;
49+
else if (!strcmp("-s", argv[1]))
50+
opt_dump_stack = 1;
51+
else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) {
52+
print_help();
53+
return 2;
54+
}
55+
56+
if (argc != 2) {
57+
fprintf(stderr, "need argument\n");
58+
print_help();
59+
return 2;
60+
}
61+
62+
arg = argv[1];
63+
64+
if (opt_dump_blocks) {
65+
err = reftable_reader_print_blocks(arg);
66+
} else if (opt_dump_table) {
67+
err = reftable_reader_print_file(arg);
68+
} else if (opt_dump_stack) {
69+
err = reftable_stack_print_directory(arg, opt_hash_id);
70+
}
71+
72+
if (err < 0) {
73+
fprintf(stderr, "%s: %s: %s\n", argv0, arg,
74+
reftable_error_str(err));
75+
return 1;
76+
}
77+
return 0;
1978
}

0 commit comments

Comments
 (0)