]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reftable/blocksource: drop malloc block source
authorPatrick Steinhardt <ps@pks.im>
Fri, 23 Aug 2024 14:12:29 +0000 (16:12 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 23 Aug 2024 15:04:46 +0000 (08:04 -0700)
The reftable blocksource provides a generic interface to read blocks via
different sources, e.g. from disk or from memory. One of the block
sources is the malloc block source, which can in theory read data from
memory. We nowadays also have a strbuf block source though, which
provides essentially the same functionality with better ergonomics.

Adapt the only remaining user of the malloc block source in our tests
to use the strbuf block source, instead, and remove the now-unused
malloc block source.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/block_test.c
reftable/blocksource.c
reftable/blocksource.h

index 90aecd5a7c6f43c28a485edf8cbd67aad374fbda..de8f426a429dd87bdb6af7500512b7883c999198 100644 (file)
@@ -34,11 +34,12 @@ static void test_block_read_write(void)
        struct block_reader br = { 0 };
        struct block_iter it = BLOCK_ITER_INIT;
        int j = 0;
+       struct strbuf block_data = STRBUF_INIT;
        struct strbuf want = STRBUF_INIT;
 
        REFTABLE_CALLOC_ARRAY(block.data, block_size);
        block.len = block_size;
-       block.source = malloc_block_source();
+       block_source_from_strbuf(&block.source, &block_data);
        block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
                          header_off, hash_size(GIT_SHA1_FORMAT_ID));
 
index eeed254ba9c2da51177eb7ed81fbf16d17ba183b..1774853011d31e85317d9b98ec3b2ebf510b8229 100644 (file)
@@ -55,26 +55,6 @@ void block_source_from_strbuf(struct reftable_block_source *bs,
        bs->arg = buf;
 }
 
-static void malloc_return_block(void *b, struct reftable_block *dest)
-{
-       if (dest->len)
-               memset(dest->data, 0xff, dest->len);
-       reftable_free(dest->data);
-}
-
-static struct reftable_block_source_vtable malloc_vtable = {
-       .return_block = &malloc_return_block,
-};
-
-static struct reftable_block_source malloc_block_source_instance = {
-       .ops = &malloc_vtable,
-};
-
-struct reftable_block_source malloc_block_source(void)
-{
-       return malloc_block_source_instance;
-}
-
 struct file_block_source {
        uint64_t size;
        unsigned char *data;
index 072e2727ad205d4319e60a7d93a62a560831edec..659a27b4063e40cef132964e0658ec5f4312e092 100644 (file)
@@ -17,6 +17,4 @@ struct reftable_block_source;
 void block_source_from_strbuf(struct reftable_block_source *bs,
                              struct strbuf *buf);
 
-struct reftable_block_source malloc_block_source(void);
-
 #endif