aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-11-23 19:59:31 +0100
committerJunio C Hamano <gitster@pobox.com>2025-11-23 12:56:44 -0800
commite030d0aeb5ebf79cdc4910e79d59e33998de78cd (patch)
treeb066fdac0de50ee4687fef2d3eb04ad782101c1f
parent595296e124f5e8a67c4669fcaeb1b28e71c2d751 (diff)
downloadgit-e030d0aeb5ebf79cdc4910e79d59e33998de78cd.tar.gz
streaming: create structure for in-core object streams
As explained in a preceding commit, we want to get rid of the union of stream-type specific data in `struct odb_read_stream`. Create a new structure for in-core object streams to move towards this design. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--streaming.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/streaming.c b/streaming.c
index a2c2d88738..35307d7229 100644
--- a/streaming.c
+++ b/streaming.c
@@ -40,11 +40,6 @@ struct odb_read_stream {
union {
struct {
- char *buf; /* from odb_read_object_info_extended() */
- unsigned long read_ptr;
- } incore;
-
- struct {
void *mapped;
unsigned long mapsize;
char hdr[32];
@@ -401,22 +396,30 @@ static int open_istream_pack_non_delta(struct odb_read_stream **out,
*
*****************************************************************/
-static int close_istream_incore(struct odb_read_stream *st)
+struct odb_incore_read_stream {
+ struct odb_read_stream base;
+ char *buf; /* from odb_read_object_info_extended() */
+ unsigned long read_ptr;
+};
+
+static int close_istream_incore(struct odb_read_stream *_st)
{
- free(st->u.incore.buf);
+ struct odb_incore_read_stream *st = (struct odb_incore_read_stream *)_st;
+ free(st->buf);
return 0;
}
-static ssize_t read_istream_incore(struct odb_read_stream *st, char *buf, size_t sz)
+static ssize_t read_istream_incore(struct odb_read_stream *_st, char *buf, size_t sz)
{
+ struct odb_incore_read_stream *st = (struct odb_incore_read_stream *)_st;
size_t read_size = sz;
- size_t remainder = st->size - st->u.incore.read_ptr;
+ size_t remainder = st->base.size - st->read_ptr;
if (remainder <= read_size)
read_size = remainder;
if (read_size) {
- memcpy(buf, st->u.incore.buf + st->u.incore.read_ptr, read_size);
- st->u.incore.read_ptr += read_size;
+ memcpy(buf, st->buf + st->read_ptr, read_size);
+ st->read_ptr += read_size;
}
return read_size;
}
@@ -426,22 +429,25 @@ static int open_istream_incore(struct odb_read_stream **out,
const struct object_id *oid)
{
struct object_info oi = OBJECT_INFO_INIT;
- struct odb_read_stream stream = {
- .close = close_istream_incore,
- .read = read_istream_incore,
+ struct odb_incore_read_stream stream = {
+ .base.close = close_istream_incore,
+ .base.read = read_istream_incore,
};
+ struct odb_incore_read_stream *st;
int ret;
- oi.typep = &stream.type;
- oi.sizep = &stream.size;
- oi.contentp = (void **)&stream.u.incore.buf;
+ oi.typep = &stream.base.type;
+ oi.sizep = &stream.base.size;
+ oi.contentp = (void **)&stream.buf;
ret = odb_read_object_info_extended(r->objects, oid, &oi,
OBJECT_INFO_DIE_IF_CORRUPT);
if (ret)
return ret;
- CALLOC_ARRAY(*out, 1);
- **out = stream;
+ CALLOC_ARRAY(st, 1);
+ *st = stream;
+ *out = &st->base;
+
return 0;
}