reftable/blocksource: adapt interface name

Adapt the name of the `strbuf` block source to no longer relate to this
interface, but instead to the `reftable_buf` interface.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:
Patrick Steinhardt 2024-10-17 06:53:59 +02:00 committed by Taylor Blau
parent be4c070a3c
commit f177d49163
6 changed files with 36 additions and 36 deletions

View File

@ -13,19 +13,19 @@ https://developers.google.com/open-source/licenses/bsd
#include "reftable-blocksource.h"
#include "reftable-error.h"
static void strbuf_return_block(void *b UNUSED, struct reftable_block *dest)
static void reftable_buf_return_block(void *b UNUSED, struct reftable_block *dest)
{
if (dest->len)
memset(dest->data, 0xff, dest->len);
reftable_free(dest->data);
}
static void strbuf_close(void *b UNUSED)
static void reftable_buf_close(void *b UNUSED)
{
}
static int strbuf_read_block(void *v, struct reftable_block *dest, uint64_t off,
uint32_t size)
static int reftable_buf_read_block(void *v, struct reftable_block *dest,
uint64_t off, uint32_t size)
{
struct reftable_buf *b = v;
assert(off + size <= b->len);
@ -37,23 +37,23 @@ static int strbuf_read_block(void *v, struct reftable_block *dest, uint64_t off,
return size;
}
static uint64_t strbuf_size(void *b)
static uint64_t reftable_buf_size(void *b)
{
return ((struct reftable_buf *)b)->len;
}
static struct reftable_block_source_vtable strbuf_vtable = {
.size = &strbuf_size,
.read_block = &strbuf_read_block,
.return_block = &strbuf_return_block,
.close = &strbuf_close,
static struct reftable_block_source_vtable reftable_buf_vtable = {
.size = &reftable_buf_size,
.read_block = &reftable_buf_read_block,
.return_block = &reftable_buf_return_block,
.close = &reftable_buf_close,
};
void block_source_from_strbuf(struct reftable_block_source *bs,
struct reftable_buf *buf)
void block_source_from_buf(struct reftable_block_source *bs,
struct reftable_buf *buf)
{
assert(!bs->ops);
bs->ops = &strbuf_vtable;
bs->ops = &reftable_buf_vtable;
bs->arg = buf;
}

View File

@ -15,7 +15,7 @@ struct reftable_block_source;
struct reftable_buf;
/* Create an in-memory block source for reading reftables */
void block_source_from_strbuf(struct reftable_block_source *bs,
struct reftable_buf *buf);
void block_source_from_buf(struct reftable_block_source *bs,
struct reftable_buf *buf);
#endif

View File

@ -34,7 +34,7 @@ static void t_ref_block_read_write(void)
REFTABLE_CALLOC_ARRAY(block.data, block_size);
check(block.data != NULL);
block.len = block_size;
block_source_from_strbuf(&block.source ,&buf);
block_source_from_buf(&block.source ,&buf);
ret = block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
check(!ret);
@ -128,7 +128,7 @@ static void t_log_block_read_write(void)
REFTABLE_CALLOC_ARRAY(block.data, block_size);
check(block.data != NULL);
block.len = block_size;
block_source_from_strbuf(&block.source ,&buf);
block_source_from_buf(&block.source ,&buf);
ret = block_writer_init(&bw, BLOCK_TYPE_LOG, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
check(!ret);
@ -218,7 +218,7 @@ static void t_obj_block_read_write(void)
REFTABLE_CALLOC_ARRAY(block.data, block_size);
check(block.data != NULL);
block.len = block_size;
block_source_from_strbuf(&block.source, &buf);
block_source_from_buf(&block.source, &buf);
ret = block_writer_init(&bw, BLOCK_TYPE_OBJ, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
check(!ret);
@ -302,7 +302,7 @@ static void t_index_block_read_write(void)
REFTABLE_CALLOC_ARRAY(block.data, block_size);
check(block.data != NULL);
block.len = block_size;
block_source_from_strbuf(&block.source, &buf);
block_source_from_buf(&block.source, &buf);
ret = block_writer_init(&bw, BLOCK_TYPE_INDEX, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
check(!ret);

View File

@ -35,7 +35,7 @@ merged_table_from_records(struct reftable_ref_record **refs,
for (size_t i = 0; i < n; i++) {
t_reftable_write_to_buf(&buf[i], refs[i], sizes[i], NULL, 0, &opts);
block_source_from_strbuf(&(*source)[i], &buf[i]);
block_source_from_buf(&(*source)[i], &buf[i]);
err = reftable_reader_new(&(*readers)[i], &(*source)[i],
"name");
@ -293,7 +293,7 @@ merged_table_from_log_records(struct reftable_log_record **logs,
for (size_t i = 0; i < n; i++) {
t_reftable_write_to_buf(&buf[i], NULL, 0, logs[i], sizes[i], &opts);
block_source_from_strbuf(&(*source)[i], &buf[i]);
block_source_from_buf(&(*source)[i], &buf[i]);
err = reftable_reader_new(&(*readers)[i], &(*source)[i],
"name");
@ -442,7 +442,7 @@ static void t_default_write_opts(void)
check(!err);
reftable_writer_free(w);
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&rd, &source, "filename");
check(!err);

View File

@ -20,7 +20,7 @@ static int t_reader_seek_once(void)
int ret;
t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
ret = reftable_reader_new(&reader, &source, "name");
check(!ret);
@ -61,7 +61,7 @@ static int t_reader_reseek(void)
int ret;
t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
ret = reftable_reader_new(&reader, &source, "name");
check(!ret);

View File

@ -24,7 +24,7 @@ static void t_buffer(void)
int n;
uint8_t in[] = "hello";
reftable_buf_add(&buf, in, sizeof(in));
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
check_int(block_source_size(&source), ==, 6);
n = block_source_read_block(&source, &out, 0, sizeof(in));
check_int(n, ==, sizeof(in));
@ -207,7 +207,7 @@ static void t_log_write_read(void)
reftable_writer_free(w);
w = NULL;
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&reader, &source, "file.log");
check(!err);
@ -298,7 +298,7 @@ static void t_log_zlib_corruption(void)
/* corrupt the data. */
buf.buf[50] ^= 0x99;
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&reader, &source, "file.log");
check(!err);
@ -328,7 +328,7 @@ static void t_table_read_write_sequential(void)
write_table(&names, &buf, N, 256, GIT_SHA1_FORMAT_ID);
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&reader, &source, "file.ref");
check(!err);
@ -380,7 +380,7 @@ static void t_table_read_api(void)
write_table(&names, &buf, N, 256, GIT_SHA1_FORMAT_ID);
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&reader, &source, "file.ref");
check(!err);
@ -416,7 +416,7 @@ static void t_table_read_write_seek(int index, int hash_id)
write_table(&names, &buf, N, 256, hash_id);
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&reader, &source, "file.ref");
check(!err);
@ -538,7 +538,7 @@ static void t_table_refs_for(int indexed)
reftable_writer_free(w);
w = NULL;
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&reader, &source, "file.ref");
check(!err);
@ -600,7 +600,7 @@ static void t_write_empty_table(void)
check_int(buf.len, ==, header_size(1) + footer_size(1));
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&rd, &source, "filename");
check(!err);
@ -806,7 +806,7 @@ static void t_write_multiple_indices(void)
check_int(stats->obj_stats.index_offset, >, 0);
check_int(stats->log_stats.index_offset, >, 0);
block_source_from_strbuf(&source, &writer_buf);
block_source_from_buf(&source, &writer_buf);
err = reftable_reader_new(&reader, &source, "filename");
check(!err);
@ -863,7 +863,7 @@ static void t_write_multi_level_index(void)
stats = reftable_writer_stats(writer);
check_int(stats->ref_stats.max_index_level, ==, 2);
block_source_from_strbuf(&source, &writer_buf);
block_source_from_buf(&source, &writer_buf);
err = reftable_reader_new(&reader, &source, "filename");
check(!err);
@ -889,7 +889,7 @@ static void t_corrupt_table_empty(void)
struct reftable_reader *reader;
int err;
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&reader, &source, "file.log");
check_int(err, ==, REFTABLE_FORMAT_ERROR);
}
@ -903,7 +903,7 @@ static void t_corrupt_table(void)
int err;
reftable_buf_add(&buf, zeros, sizeof(zeros));
block_source_from_strbuf(&source, &buf);
block_source_from_buf(&source, &buf);
err = reftable_reader_new(&reader, &source, "file.log");
check_int(err, ==, REFTABLE_FORMAT_ERROR);