diff options
| author | Patrick Steinhardt <ps@pks.im> | 2025-04-07 15:16:28 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-04-07 14:53:13 -0700 |
| commit | e0011188ca0edc31ed861357014fd0f229d67448 (patch) | |
| tree | f398174d0a24898504f8b2c872aad3f98e6d2925 /reftable/table.c | |
| parent | 0f8ee94b636b5ab183c62b8fdd26c1611c2b86f4 (diff) | |
| download | git-e0011188ca0edc31ed861357014fd0f229d67448.tar.xz | |
reftable/table: move printing logic into test helper
The logic to print individual blocks in a table is hosted in the
reftable library. This is only the case due to historical reasons though
because users of the library had no interfaces to read blocks one by
one. Otherwise, printing individual blocks has no place in the reftable
library given that the format will not be generic in the first place.
We have now grown a public interface to iterate through blocks contained
in a table, and thus we can finally move the logic to print them into
the test helper.
Move over the logic and refactor it accordingly. Note that the iterator
also trivially allows us to access index sections, which we previously
didn't print at all. This omission wasn't intentional though, so start
dumping those sections as well so that we can assert that indices are
written as expected.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/table.c')
| -rw-r--r-- | reftable/table.c | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/reftable/table.c b/reftable/table.c index 1af3942322..ee83127615 100644 --- a/reftable/table.c +++ b/reftable/table.c @@ -740,71 +740,6 @@ uint64_t reftable_table_min_update_index(struct reftable_table *t) 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) { |
