return t->min_update_index;
}
-int reftable_table_print_blocks(const char *tablename)
-{
- struct {
- const char *name;
- int type;
- } sections[] = {
- {
- .name = "ref",
- .type = REFTABLE_BLOCK_TYPE_REF,
- },
- {
- .name = "obj",
- .type = REFTABLE_BLOCK_TYPE_OBJ,
- },
- {
- .name = "log",
- .type = REFTABLE_BLOCK_TYPE_LOG,
- },
- };
- struct reftable_block_source src = { 0 };
- struct reftable_table *table = NULL;
- struct table_iter ti = { 0 };
- size_t i;
- int err;
-
- err = reftable_block_source_from_file(&src, tablename);
- if (err < 0)
- goto done;
-
- err = reftable_table_new(&table, &src, tablename);
- if (err < 0)
- goto done;
-
- table_iter_init(&ti, table);
-
- printf("header:\n");
- printf(" block_size: %d\n", table->block_size);
-
- for (i = 0; i < sizeof(sections) / sizeof(*sections); i++) {
- err = table_iter_seek_start(&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.block.restart_off);
- printf(" restarts: %u\n", ti.block.restart_count);
-
- err = table_iter_next_block(&ti);
- if (err < 0)
- goto done;
- if (err > 0)
- break;
- }
- }
-
-done:
- reftable_table_decref(table);
- table_iter_close(&ti);
- return err;
-}
-
int reftable_table_iterator_init(struct reftable_table_iterator *it,
struct reftable_table *t)
{
#include "hash.h"
#include "hex.h"
#include "reftable/system.h"
+#include "reftable/reftable-constants.h"
#include "reftable/reftable-error.h"
#include "reftable/reftable-merged.h"
#include "reftable/reftable-stack.h"
"\n");
}
+static int dump_blocks(const char *tablename)
+{
+ struct reftable_table_iterator ti = { 0 };
+ struct reftable_block_source src = { 0 };
+ struct reftable_table *table = NULL;
+ uint8_t section_type = 0;
+ int err;
+
+ err = reftable_block_source_from_file(&src, tablename);
+ if (err < 0)
+ goto done;
+
+ err = reftable_table_new(&table, &src, tablename);
+ if (err < 0)
+ goto done;
+
+ err = reftable_table_iterator_init(&ti, table);
+ if (err < 0)
+ goto done;
+
+ printf("header:\n");
+ printf(" block_size: %d\n", table->block_size);
+
+ while (1) {
+ const struct reftable_block *block;
+
+ err = reftable_table_iterator_next(&ti, &block);
+ if (err < 0)
+ goto done;
+ if (err > 0)
+ break;
+
+ if (block->block_type != section_type) {
+ const char *section;
+ switch (block->block_type) {
+ case REFTABLE_BLOCK_TYPE_LOG:
+ section = "log";
+ break;
+ case REFTABLE_BLOCK_TYPE_REF:
+ section = "ref";
+ break;
+ case REFTABLE_BLOCK_TYPE_OBJ:
+ section = "obj";
+ break;
+ case REFTABLE_BLOCK_TYPE_INDEX:
+ section = "idx";
+ break;
+ default:
+ err = -1;
+ goto done;
+ }
+
+ section_type = block->block_type;
+ printf("%s:\n", section);
+ }
+
+ printf(" - length: %u\n", block->restart_off);
+ printf(" restarts: %u\n", block->restart_count);
+ }
+
+done:
+ reftable_table_iterator_release(&ti);
+ reftable_table_decref(table);
+ return err;
+}
+
static int dump_table(struct reftable_merged_table *mt)
{
struct reftable_iterator it = { NULL };
arg = argv[1];
if (opt_dump_blocks) {
- err = reftable_table_print_blocks(arg);
+ err = dump_blocks(arg);
} else if (opt_dump_table) {
err = dump_reftable(arg);
} else if (opt_dump_stack) {