aboutsummaryrefslogtreecommitdiff
path: root/reftable/blocksource.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-04-07 15:16:15 +0200
committerJunio C Hamano <gitster@pobox.com>2025-04-07 14:53:09 -0700
commit1ac4e5e83d997887dcd051c89861292a45a3db8c (patch)
treed843aabb8b472a1f4a523c0552f270b03f784904 /reftable/blocksource.c
parentb648bd654947db06e5549d724f46d3660ac11e19 (diff)
downloadgit-1ac4e5e83d997887dcd051c89861292a45a3db8c.tar.xz
reftable/blocksource: consolidate code into a single file
The code that implements block sources is distributed across a couple of files. Consolidate all of it into "reftable/blocksource.c" and its accompanying header so that it is easier to locate and more self contained. While at it, rename some of the functions to have properly scoped names. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/blocksource.c')
-rw-r--r--reftable/blocksource.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/reftable/blocksource.c b/reftable/blocksource.c
index 1397cbe780..bc785506fb 100644
--- a/reftable/blocksource.c
+++ b/reftable/blocksource.c
@@ -13,6 +13,41 @@
#include "reftable-blocksource.h"
#include "reftable-error.h"
+void block_source_return_block(struct reftable_block *block)
+{
+ struct reftable_block_source source = block->source;
+ if (block && source.ops)
+ source.ops->return_block(source.arg, block);
+ block->data = NULL;
+ block->len = 0;
+ block->source.ops = NULL;
+ block->source.arg = NULL;
+}
+
+void block_source_close(struct reftable_block_source *source)
+{
+ if (!source->ops) {
+ return;
+ }
+
+ source->ops->close(source->arg);
+ source->ops = NULL;
+}
+
+ssize_t block_source_read_block(struct reftable_block_source *source,
+ struct reftable_block *dest, uint64_t off,
+ uint32_t size)
+{
+ ssize_t result = source->ops->read_block(source->arg, dest, off, size);
+ dest->source = *source;
+ return result;
+}
+
+uint64_t block_source_size(struct reftable_block_source *source)
+{
+ return source->ops->size(source->arg);
+}
+
static void reftable_buf_return_block(void *b REFTABLE_UNUSED, struct reftable_block *dest)
{
if (dest->len)