streaming: drop redundant type and size pointers

In the preceding commits we have turned `struct odb_read_stream` into a publicly visible structure. Furthermore, this structure now contains the type and size of the object that we are about to stream. Consequently, the out-pointers that we used before to propagate the type and size of the streamed object are now somewhat redundant with the data contained in the structure itself. Drop these out-pointers and adapt callers accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 23, 2025 at 19:59 UTC 7b940286527ec2175dffbb317f47e080bb37cf3e
7 files changed +15 -30
archive-tar.c
+1 -3
@@ -130,12 +130,10 @@ static void write_trailer(void)
130 static int stream_blocked(struct repository *r, const struct object_id *oid)
131 {
132 struct odb_read_stream *st;
133 - enum object_type type;
134 - unsigned long sz;
133 char buf[BLOCKSIZE];
134 ssize_t readlen;
135
138 - st = odb_read_stream_open(r->objects, oid, &type, &sz, NULL);
136 + st = odb_read_stream_open(r->objects, oid, NULL);
137 if (!st)
138 return error(_("cannot stream blob %s"), oid_to_hex(oid));
139 for (;;) {
archive-zip.c
+2 -3
@@ -347,12 +347,11 @@ static int write_zip_entry(struct archiver_args *args,
347 method = ZIP_METHOD_DEFLATE;
348
349 if (!buffer) {
350 - enum object_type type;
351 - stream = odb_read_stream_open(args->repo->objects, oid,
352 - &type, &size, NULL);
350 + stream = odb_read_stream_open(args->repo->objects, oid, NULL);
351 if (!stream)
352 return error(_("cannot stream blob %s"),
353 oid_to_hex(oid));
354 + size = stream->size;
355 flags |= ZIP_STREAM;
356 out = NULL;
357 } else {
builtin/index-pack.c
+2 -5
@@ -798,8 +798,6 @@ static int compare_objects(const unsigned char *buf, unsigned long size,
798 static int check_collison(struct object_entry *entry)
799 {
800 struct compare_data data;
801 - enum object_type type;
802 - unsigned long size;
801
802 if (entry->size <= repo_settings_get_big_file_threshold(the_repository) ||
803 entry->type != OBJ_BLOB)
@@ -807,11 +805,10 @@ static int check_collison(struct object_entry *entry)
805
806 memset(&data, 0, sizeof(data));
807 data.entry = entry;
810 - data.st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
811 - &type, &size, NULL);
808 + data.st = odb_read_stream_open(the_repository->objects, &entry->idx.oid, NULL);
809 if (!data.st)
810 return -1;
814 - if (size != entry->size || type != entry->type)
811 + if (data.st->size != entry->size || data.st->type != entry->type)
812 die(_("SHA1 COLLISION FOUND WITH %s !"),
813 oid_to_hex(&entry->idx.oid));
814 unpack_data(entry, compare_objects, &data);
builtin/pack-objects.c
+4 -2
@@ -521,9 +521,11 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
521 oe_size_greater_than(&to_pack, entry,
522 repo_settings_get_big_file_threshold(the_repository)) &&
523 (st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
524 - &type, &size, NULL)) != NULL)
524 + NULL)) != NULL) {
525 buf = NULL;
526 - else {
526 + type = st->type;
527 + size = st->size;
528 + } else {
529 buf = odb_read_object(the_repository->objects,
530 &entry->idx.oid, &type,
531 &size);
object-file.c
+2 -4
@@ -132,19 +132,17 @@ int check_object_signature(struct repository *r, const struct object_id *oid,
132 int stream_object_signature(struct repository *r, const struct object_id *oid)
133 {
134 struct object_id real_oid;
135 - unsigned long size;
136 - enum object_type obj_type;
135 struct odb_read_stream *st;
136 struct git_hash_ctx c;
137 char hdr[MAX_HEADER_LEN];
138 int hdrlen;
139
142 - st = odb_read_stream_open(r->objects, oid, &obj_type, &size, NULL);
140 + st = odb_read_stream_open(r->objects, oid, NULL);
141 if (!st)
142 return -1;
143
144 /* Generate the header */
147 - hdrlen = format_object_header(hdr, sizeof(hdr), obj_type, size);
145 + hdrlen = format_object_header(hdr, sizeof(hdr), st->type, st->size);
146
147 /* Sha1.. */
148 r->hash_algo->init_fn(&c);
odb/streaming.c
+2 -8
@@ -214,8 +214,6 @@ ssize_t odb_read_stream_read(struct odb_read_stream *st, void *buf, size_t sz)
214
215 struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
216 const struct object_id *oid,
217 - enum object_type *type,
218 - unsigned long *size,
217 struct stream_filter *filter)
218 {
219 struct odb_read_stream *st;
@@ -235,8 +233,6 @@ struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
233 st = nst;
234 }
235
238 - *size = st->size;
239 - *type = st->type;
236 return st;
237 }
238
@@ -247,18 +243,16 @@ int odb_stream_blob_to_fd(struct object_database *odb,
243 int can_seek)
244 {
245 struct odb_read_stream *st;
250 - enum object_type type;
251 - unsigned long sz;
246 ssize_t kept = 0;
247 int result = -1;
248
255 - st = odb_read_stream_open(odb, oid, &type, &sz, filter);
249 + st = odb_read_stream_open(odb, oid, filter);
250 if (!st) {
251 if (filter)
252 free_stream_filter(filter);
253 return result;
254 }
261 - if (type != OBJ_BLOB)
255 + if (st->type != OBJ_BLOB)
256 goto close_and_exit;
257 for (;;) {
258 char buf[1024 * 16];
odb/streaming.h
+2 -5
@@ -25,16 +25,13 @@ struct odb_read_stream {
25 };
26
27 /*
28 - * Create a new object stream for the given object database. Populates the type
29 - * and size pointers with the object's info. An optional filter can be used to
30 - * transform the object's content.
28 + * Create a new object stream for the given object database. An optional filter
29 + * can be used to transform the object's content.
30 *
31 * Returns the stream on success, a `NULL` pointer otherwise.
32 */
33 struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
34 const struct object_id *oid,
36 - enum object_type *type,
37 - unsigned long *size,
35 struct stream_filter *filter);
36
37 /*