reftable/block: better grouping of functions

Function definitions and declaration of `struct block_reader` and `struct block_iter` are somewhat mixed up, making it hard to see which functions belong together. Rearrange them. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 8, 2024 at 14:16 UTC aac8c03cc45e047b1b721a61580c920995bf43a3
2 files changed +36 -36
reftable/block.c
+25 -25
@@ -175,11 +175,6 @@ int block_writer_finish(struct block_writer *w)
175 return w->next;
176 }
177
178 -uint8_t block_reader_type(struct block_reader *r)
179 -{
180 - return r->block.data[r->header_off];
181 -}
182 -
178 int block_reader_init(struct block_reader *br, struct reftable_block *block,
179 uint32_t header_off, uint32_t table_block_size,
180 int hash_size)
@@ -261,6 +256,31 @@ done:
256 return err;
257 }
258
259 +uint8_t block_reader_type(struct block_reader *r)
260 +{
261 + return r->block.data[r->header_off];
262 +}
263 +
264 +int block_reader_first_key(struct block_reader *br, struct strbuf *key)
265 +{
266 + int off = br->header_off + 4, n;
267 + struct string_view in = {
268 + .buf = br->block.data + off,
269 + .len = br->block_len - off,
270 + };
271 + uint8_t extra = 0;
272 +
273 + strbuf_reset(key);
274 +
275 + n = reftable_decode_key(key, &extra, in);
276 + if (n < 0)
277 + return n;
278 + if (!key->len)
279 + return REFTABLE_FORMAT_ERROR;
280 +
281 + return 0;
282 +}
283 +
284 static uint32_t block_reader_restart_offset(struct block_reader *br, int i)
285 {
286 return get_be24(br->restart_bytes + 3 * i);
@@ -353,26 +373,6 @@ int block_iter_next(struct block_iter *it, struct reftable_record *rec)
373 return 0;
374 }
375
356 -int block_reader_first_key(struct block_reader *br, struct strbuf *key)
357 -{
358 - int off = br->header_off + 4, n;
359 - struct string_view in = {
360 - .buf = br->block.data + off,
361 - .len = br->block_len - off,
362 - };
363 - uint8_t extra = 0;
364 -
365 - strbuf_reset(key);
366 -
367 - n = reftable_decode_key(key, &extra, in);
368 - if (n < 0)
369 - return n;
370 - if (!key->len)
371 - return REFTABLE_FORMAT_ERROR;
372 -
373 - return 0;
374 -}
375 -
376 void block_iter_close(struct block_iter *it)
377 {
378 strbuf_release(&it->last_key);
reftable/block.h
+11 -11
@@ -76,6 +76,17 @@ struct block_reader {
76 uint32_t full_block_size;
77 };
78
79 +/* initializes a block reader. */
80 +int block_reader_init(struct block_reader *br, struct reftable_block *bl,
81 + uint32_t header_off, uint32_t table_block_size,
82 + int hash_size);
83 +
84 +/* Returns the block type (eg. 'r' for refs) */
85 +uint8_t block_reader_type(struct block_reader *r);
86 +
87 +/* Decodes the first key in the block */
88 +int block_reader_first_key(struct block_reader *br, struct strbuf *key);
89 +
90 /* Iterate over entries in a block */
91 struct block_iter {
92 /* offset within the block of the next entry to read. */
@@ -92,11 +103,6 @@ struct block_iter {
103 .scratch = STRBUF_INIT, \
104 }
105
95 -/* initializes a block reader. */
96 -int block_reader_init(struct block_reader *br, struct reftable_block *bl,
97 - uint32_t header_off, uint32_t table_block_size,
98 - int hash_size);
99 -
106 /* Position `it` at start of the block */
107 void block_iter_seek_start(struct block_iter *it, struct block_reader *br);
108
@@ -104,12 +110,6 @@ void block_iter_seek_start(struct block_iter *it, struct block_reader *br);
110 int block_iter_seek_key(struct block_iter *it, struct block_reader *br,
111 struct strbuf *want);
112
107 -/* Returns the block type (eg. 'r' for refs) */
108 -uint8_t block_reader_type(struct block_reader *r);
109 -
110 -/* Decodes the first key in the block */
111 -int block_reader_first_key(struct block_reader *br, struct strbuf *key);
112 -
113 void block_iter_copy_from(struct block_iter *dest, struct block_iter *src);
114
115 /* return < 0 for error, 0 for OK, > 0 for EOF. */