t/helper: inline `reftable_table_print()`
Move `reftable_table_print()` into the "dump-reftable" helper. This follows the same reasoning as the preceding commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Aug 22, 2024 at 08:35 UTC
64a5b7a8ca32724699ebfb62f278bae873cc018d
3 files changed
+50
-52
reftable/generic.c
-47
@@ -61,53 +61,6 @@ done:
61
return err;
62
}
63
64
-int reftable_table_print(struct reftable_table *tab) {
65
- struct reftable_iterator it = { NULL };
66
- struct reftable_ref_record ref = { NULL };
67
- struct reftable_log_record log = { NULL };
68
- uint32_t hash_id = reftable_table_hash_id(tab);
69
- int err;
70
-
71
- reftable_table_init_ref_iter(tab, &it);
72
-
73
- err = reftable_iterator_seek_ref(&it, "");
74
- if (err < 0)
75
- return err;
76
-
77
- while (1) {
78
- err = reftable_iterator_next_ref(&it, &ref);
79
- if (err > 0) {
80
- break;
81
- }
82
- if (err < 0) {
83
- return err;
84
- }
85
- reftable_ref_record_print(&ref, hash_id);
86
- }
87
- reftable_iterator_destroy(&it);
88
- reftable_ref_record_release(&ref);
89
-
90
- reftable_table_init_log_iter(tab, &it);
91
-
92
- err = reftable_iterator_seek_log(&it, "");
93
- if (err < 0)
94
- return err;
95
-
96
- while (1) {
97
- err = reftable_iterator_next_log(&it, &log);
98
- if (err > 0) {
99
- break;
100
- }
101
- if (err < 0) {
102
- return err;
103
- }
104
- reftable_log_record_print(&log, hash_id);
105
- }
106
- reftable_iterator_destroy(&it);
107
- reftable_log_record_release(&log);
108
- return 0;
109
-}
110
-
64
uint64_t reftable_table_max_update_index(struct reftable_table *tab)
65
{
66
return tab->ops->max_update_index(tab->table_arg);
reftable/reftable-generic.h
-3
@@ -41,7 +41,4 @@ uint64_t reftable_table_min_update_index(struct reftable_table *tab);
41
int reftable_table_read_ref(struct reftable_table *tab, const char *name,
42
struct reftable_ref_record *ref);
43
44
-/* dump table contents onto stdout for debugging */
45
-int reftable_table_print(struct reftable_table *tab);
46
-
44
#endif
t/helper/test-reftable.c
+50
-2
@@ -30,6 +30,54 @@ static void print_help(void)
30
"\n");
31
}
32
33
+static int dump_table(struct reftable_table *tab)
34
+{
35
+ struct reftable_iterator it = { NULL };
36
+ struct reftable_ref_record ref = { NULL };
37
+ struct reftable_log_record log = { NULL };
38
+ uint32_t hash_id = reftable_table_hash_id(tab);
39
+ int err;
40
+
41
+ reftable_table_init_ref_iter(tab, &it);
42
+
43
+ err = reftable_iterator_seek_ref(&it, "");
44
+ if (err < 0)
45
+ return err;
46
+
47
+ while (1) {
48
+ err = reftable_iterator_next_ref(&it, &ref);
49
+ if (err > 0) {
50
+ break;
51
+ }
52
+ if (err < 0) {
53
+ return err;
54
+ }
55
+ reftable_ref_record_print(&ref, hash_id);
56
+ }
57
+ reftable_iterator_destroy(&it);
58
+ reftable_ref_record_release(&ref);
59
+
60
+ reftable_table_init_log_iter(tab, &it);
61
+
62
+ err = reftable_iterator_seek_log(&it, "");
63
+ if (err < 0)
64
+ return err;
65
+
66
+ while (1) {
67
+ err = reftable_iterator_next_log(&it, &log);
68
+ if (err > 0) {
69
+ break;
70
+ }
71
+ if (err < 0) {
72
+ return err;
73
+ }
74
+ reftable_log_record_print(&log, hash_id);
75
+ }
76
+ reftable_iterator_destroy(&it);
77
+ reftable_log_record_release(&log);
78
+ return 0;
79
+}
80
+
81
static int dump_stack(const char *stackdir, uint32_t hash_id)
82
{
83
struct reftable_stack *stack = NULL;
@@ -43,7 +91,7 @@ static int dump_stack(const char *stackdir, uint32_t hash_id)
91
92
merged = reftable_stack_merged_table(stack);
93
reftable_table_from_merged_table(&table, merged);
46
- err = reftable_table_print(&table);
94
+ err = dump_table(&table);
95
done:
96
if (stack)
97
reftable_stack_destroy(stack);
@@ -64,7 +112,7 @@ static int dump_reftable(const char *tablename)
112
goto done;
113
114
reftable_table_from_reader(&tab, r);
67
- err = reftable_table_print(&tab);
115
+ err = dump_table(&tab);
116
done:
117
reftable_reader_free(r);
118
return err;