2
#include "hash.h"
3
#include "hex.h"
4
#include "reftable/system.h"
5
+#include "reftable/reftable-constants.h"
6
#include "reftable/reftable-error.h"
7
#include "reftable/reftable-merged.h"
8
#include "reftable/reftable-stack.h"
21
"\n");
22
}
23
24
+static int dump_blocks(const char *tablename)
25
+{
26
+ struct reftable_table_iterator ti = { 0 };
27
+ struct reftable_block_source src = { 0 };
28
+ struct reftable_table *table = NULL;
29
+ uint8_t section_type = 0;
30
+ int err;
31
+
32
+ err = reftable_block_source_from_file(&src, tablename);
33
+ if (err < 0)
34
+ goto done;
35
+
36
+ err = reftable_table_new(&table, &src, tablename);
37
+ if (err < 0)
38
+ goto done;
39
+
40
+ err = reftable_table_iterator_init(&ti, table);
41
+ if (err < 0)
42
+ goto done;
43
+
44
+ printf("header:\n");
45
+ printf(" block_size: %d\n", table->block_size);
46
+
47
+ while (1) {
48
+ const struct reftable_block *block;
49
+
50
+ err = reftable_table_iterator_next(&ti, &block);
51
+ if (err < 0)
52
+ goto done;
53
+ if (err > 0)
54
+ break;
55
+
56
+ if (block->block_type != section_type) {
57
+ const char *section;
58
+ switch (block->block_type) {
59
+ case REFTABLE_BLOCK_TYPE_LOG:
60
+ section = "log";
61
+ break;
62
+ case REFTABLE_BLOCK_TYPE_REF:
63
+ section = "ref";
64
+ break;
65
+ case REFTABLE_BLOCK_TYPE_OBJ:
66
+ section = "obj";
67
+ break;
68
+ case REFTABLE_BLOCK_TYPE_INDEX:
69
+ section = "idx";
70
+ break;
71
+ default:
72
+ err = -1;
73
+ goto done;
74
+ }
75
+
76
+ section_type = block->block_type;
77
+ printf("%s:\n", section);
78
+ }
79
+
80
+ printf(" - length: %u\n", block->restart_off);
81
+ printf(" restarts: %u\n", block->restart_count);
82
+ }
83
+
84
+done:
85
+ reftable_table_iterator_release(&ti);
86
+ reftable_table_decref(table);
87
+ return err;
88
+}
89
+
90
static int dump_table(struct reftable_merged_table *mt)
91
{
92
struct reftable_iterator it = { NULL };
251
arg = argv[1];
252
253
if (opt_dump_blocks) {
187
- err = reftable_table_print_blocks(arg);
254
+ err = dump_blocks(arg);
255
} else if (opt_dump_table) {
256
err = dump_reftable(arg);
257
} else if (opt_dump_stack) {