aboutsummaryrefslogtreecommitdiff
path: root/reftable
diff options
context:
space:
mode:
Diffstat (limited to 'reftable')
-rw-r--r--reftable/dump.c8
-rw-r--r--reftable/reader.c63
-rw-r--r--reftable/reftable-reader.h2
3 files changed, 72 insertions, 1 deletions
diff --git a/reftable/dump.c b/reftable/dump.c
index 586f3eb288..41abbb8ecf 100644
--- a/reftable/dump.c
+++ b/reftable/dump.c
@@ -48,6 +48,7 @@ static void print_help(void)
printf("usage: dump [-cst] arg\n\n"
"options: \n"
" -c compact\n"
+ " -b dump blocks\n"
" -t dump table\n"
" -s dump stack\n"
" -6 sha256 hash format\n"
@@ -58,6 +59,7 @@ static void print_help(void)
int reftable_dump_main(int argc, char *const *argv)
{
int err = 0;
+ int opt_dump_blocks = 0;
int opt_dump_table = 0;
int opt_dump_stack = 0;
int opt_compact = 0;
@@ -67,6 +69,8 @@ int reftable_dump_main(int argc, char *const *argv)
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]))
@@ -88,7 +92,9 @@ int reftable_dump_main(int argc, char *const *argv)
arg = argv[1];
- if (opt_dump_table) {
+ 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);
diff --git a/reftable/reader.c b/reftable/reader.c
index 481dff10d4..f23c8523db 100644
--- a/reftable/reader.c
+++ b/reftable/reader.c
@@ -856,3 +856,66 @@ done:
reftable_reader_free(r);
return err;
}
+
+int reftable_reader_print_blocks(const char *tablename)
+{
+ struct {
+ const char *name;
+ int type;
+ } sections[] = {
+ {
+ .name = "ref",
+ .type = BLOCK_TYPE_REF,
+ },
+ {
+ .name = "obj",
+ .type = BLOCK_TYPE_OBJ,
+ },
+ {
+ .name = "log",
+ .type = BLOCK_TYPE_LOG,
+ },
+ };
+ struct reftable_block_source src = { 0 };
+ struct table_iter ti = TABLE_ITER_INIT;
+ struct reftable_reader *r = NULL;
+ size_t i;
+ int err;
+
+ err = reftable_block_source_from_file(&src, tablename);
+ if (err < 0)
+ goto done;
+
+ err = reftable_new_reader(&r, &src, tablename);
+ if (err < 0)
+ goto done;
+
+ printf("header:\n");
+ printf(" block_size: %d\n", r->block_size);
+
+ for (i = 0; i < ARRAY_SIZE(sections); i++) {
+ err = reader_start(r, &ti, sections[i].type, 0);
+ if (err < 0)
+ goto done;
+ if (err > 0)
+ continue;
+
+ printf("%s:\n", sections[i].name);
+
+ while (1) {
+ printf(" - length: %u\n", ti.br.block_len);
+ printf(" restarts: %u\n", ti.br.restart_count);
+
+ err = table_iter_next_block(&ti);
+ if (err < 0)
+ goto done;
+ if (err > 0)
+ break;
+ }
+ }
+
+done:
+ reftable_reader_free(r);
+ table_iter_close(&ti);
+ return err;
+}
diff --git a/reftable/reftable-reader.h b/reftable/reftable-reader.h
index 4a4bc2fdf8..4a04857773 100644
--- a/reftable/reftable-reader.h
+++ b/reftable/reftable-reader.h
@@ -97,5 +97,7 @@ void reftable_table_from_reader(struct reftable_table *tab,
/* print table onto stdout for debugging. */
int reftable_reader_print_file(const char *tablename);
+/* print blocks onto stdout for debugging. */
+int reftable_reader_print_blocks(const char *tablename);
#endif