reftable/table: move reading block into block reader

The logic to read blocks from a reftable is scattered across both the
table and the block subsystems. Besides causing somewhat fuzzy
responsibilities, it also means that we have to awkwardly pass around
the ownership of blocks between the subsystems.

Refactor the code so that we stop passing the block when initializing a
reader, but instead by passing in the block source plus the offset at
which we're supposed to read a block. Like this, the ownership of the
block itself doesn't need to get handed over as the block reader is the
one owning the block right from the start.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-04-07 15:16:17 +02:00
committed by Junio C Hamano
parent ba620d296a
commit fd888311fb
4 changed files with 107 additions and 129 deletions

View File

@@ -89,12 +89,14 @@ struct block_reader {
/* size of the data in the file. For log blocks, this is the compressed
* size. */
uint32_t full_block_size;
uint8_t block_type;
};
/* initializes a block reader. */
int block_reader_init(struct block_reader *br, struct reftable_block *bl,
uint32_t header_off, uint32_t table_block_size,
uint32_t hash_size);
int block_reader_init(struct block_reader *br,
struct reftable_block_source *source,
uint32_t offset, uint32_t header_size,
uint32_t table_block_size, uint32_t hash_size);
void block_reader_release(struct block_reader *br);