Files
git/t/helper/test-reftable.c
Patrick Steinhardt 2b06b28fd6 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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-08-22 07:59:47 -07:00

79 lines
1.8 KiB
C

#include "reftable/system.h"
#include "reftable/reftable-error.h"
#include "reftable/reftable-reader.h"
#include "reftable/reftable-stack.h"
#include "reftable/reftable-tests.h"
#include "test-tool.h"
int cmd__reftable(int argc, const char **argv)
{
/* test from simple to complex. */
block_test_main(argc, argv);
tree_test_main(argc, argv);
pq_test_main(argc, argv);
readwrite_test_main(argc, argv);
stack_test_main(argc, argv);
return 0;
}
static void print_help(void)
{
printf("usage: dump [-st] arg\n\n"
"options: \n"
" -b dump blocks\n"
" -t dump table\n"
" -s dump stack\n"
" -6 sha256 hash format\n"
" -h this help\n"
"\n");
}
int cmd__dump_reftable(int argc, const char **argv)
{
int err = 0;
int opt_dump_blocks = 0;
int opt_dump_table = 0;
int opt_dump_stack = 0;
uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID;
const char *arg = NULL, *argv0 = argv[0];
for (; argc > 1; argv++, argc--)
if (*argv[1] != '-')
break;
else if (!strcmp("-b", argv[1]))
opt_dump_blocks = 1;
else if (!strcmp("-t", argv[1]))
opt_dump_table = 1;
else if (!strcmp("-6", argv[1]))
opt_hash_id = GIT_SHA256_FORMAT_ID;
else if (!strcmp("-s", argv[1]))
opt_dump_stack = 1;
else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) {
print_help();
return 2;
}
if (argc != 2) {
fprintf(stderr, "need argument\n");
print_help();
return 2;
}
arg = argv[1];
if (opt_dump_blocks) {
err = reftable_reader_print_blocks(arg);
} else if (opt_dump_table) {
err = reftable_reader_print_file(arg);
} else if (opt_dump_stack) {
err = reftable_stack_print_directory(arg, opt_hash_id);
}
if (err < 0) {
fprintf(stderr, "%s: %s: %s\n", argv0, arg,
reftable_error_str(err));
return 1;
}
return 0;
}