mirror of
https://github.com/git/git.git
synced 2024-05-29 14:26:11 +02:00
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>
This commit is contained in:
parent
42c7bdc36d
commit
aac8c03cc4
|
@ -175,11 +175,6 @@ int block_writer_finish(struct block_writer *w)
|
|||
return w->next;
|
||||
}
|
||||
|
||||
uint8_t block_reader_type(struct block_reader *r)
|
||||
{
|
||||
return r->block.data[r->header_off];
|
||||
}
|
||||
|
||||
int block_reader_init(struct block_reader *br, struct reftable_block *block,
|
||||
uint32_t header_off, uint32_t table_block_size,
|
||||
int hash_size)
|
||||
|
@ -261,6 +256,31 @@ int block_reader_init(struct block_reader *br, struct reftable_block *block,
|
|||
return err;
|
||||
}
|
||||
|
||||
uint8_t block_reader_type(struct block_reader *r)
|
||||
{
|
||||
return r->block.data[r->header_off];
|
||||
}
|
||||
|
||||
int block_reader_first_key(struct block_reader *br, struct strbuf *key)
|
||||
{
|
||||
int off = br->header_off + 4, n;
|
||||
struct string_view in = {
|
||||
.buf = br->block.data + off,
|
||||
.len = br->block_len - off,
|
||||
};
|
||||
uint8_t extra = 0;
|
||||
|
||||
strbuf_reset(key);
|
||||
|
||||
n = reftable_decode_key(key, &extra, in);
|
||||
if (n < 0)
|
||||
return n;
|
||||
if (!key->len)
|
||||
return REFTABLE_FORMAT_ERROR;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t block_reader_restart_offset(struct block_reader *br, int i)
|
||||
{
|
||||
return get_be24(br->restart_bytes + 3 * i);
|
||||
|
@ -353,26 +373,6 @@ int block_iter_next(struct block_iter *it, struct reftable_record *rec)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int block_reader_first_key(struct block_reader *br, struct strbuf *key)
|
||||
{
|
||||
int off = br->header_off + 4, n;
|
||||
struct string_view in = {
|
||||
.buf = br->block.data + off,
|
||||
.len = br->block_len - off,
|
||||
};
|
||||
uint8_t extra = 0;
|
||||
|
||||
strbuf_reset(key);
|
||||
|
||||
n = reftable_decode_key(key, &extra, in);
|
||||
if (n < 0)
|
||||
return n;
|
||||
if (!key->len)
|
||||
return REFTABLE_FORMAT_ERROR;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void block_iter_close(struct block_iter *it)
|
||||
{
|
||||
strbuf_release(&it->last_key);
|
||||
|
|
|
@ -76,6 +76,17 @@ struct block_reader {
|
|||
uint32_t full_block_size;
|
||||
};
|
||||
|
||||
/* 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,
|
||||
int hash_size);
|
||||
|
||||
/* Returns the block type (eg. 'r' for refs) */
|
||||
uint8_t block_reader_type(struct block_reader *r);
|
||||
|
||||
/* Decodes the first key in the block */
|
||||
int block_reader_first_key(struct block_reader *br, struct strbuf *key);
|
||||
|
||||
/* Iterate over entries in a block */
|
||||
struct block_iter {
|
||||
/* offset within the block of the next entry to read. */
|
||||
|
@ -92,11 +103,6 @@ struct block_iter {
|
|||
.scratch = STRBUF_INIT, \
|
||||
}
|
||||
|
||||
/* 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,
|
||||
int hash_size);
|
||||
|
||||
/* Position `it` at start of the block */
|
||||
void block_iter_seek_start(struct block_iter *it, struct block_reader *br);
|
||||
|
||||
|
@ -104,12 +110,6 @@ void block_iter_seek_start(struct block_iter *it, struct block_reader *br);
|
|||
int block_iter_seek_key(struct block_iter *it, struct block_reader *br,
|
||||
struct strbuf *want);
|
||||
|
||||
/* Returns the block type (eg. 'r' for refs) */
|
||||
uint8_t block_reader_type(struct block_reader *r);
|
||||
|
||||
/* Decodes the first key in the block */
|
||||
int block_reader_first_key(struct block_reader *br, struct strbuf *key);
|
||||
|
||||
void block_iter_copy_from(struct block_iter *dest, struct block_iter *src);
|
||||
|
||||
/* return < 0 for error, 0 for OK, > 0 for EOF. */
|
||||
|
|
Loading…
Reference in New Issue