]> git.ipfire.org Git - thirdparty/git.git/commitdiff
streaming: drop redundant type and size pointers
authorPatrick Steinhardt <ps@pks.im>
Sun, 23 Nov 2025 18:59:44 +0000 (19:59 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 23 Nov 2025 20:56:46 +0000 (12:56 -0800)
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>
archive-tar.c
archive-zip.c
builtin/index-pack.c
builtin/pack-objects.c
object-file.c
odb/streaming.c
odb/streaming.h

index 494b9f0667a523fe7ea333976103e1232d27f126..0fc70d13a8807eb51c9e44b494ec2aadbd2d69db 100644 (file)
@@ -130,12 +130,10 @@ static void write_trailer(void)
 static int stream_blocked(struct repository *r, const struct object_id *oid)
 {
        struct odb_read_stream *st;
-       enum object_type type;
-       unsigned long sz;
        char buf[BLOCKSIZE];
        ssize_t readlen;
 
-       st = odb_read_stream_open(r->objects, oid, &type, &sz, NULL);
+       st = odb_read_stream_open(r->objects, oid, NULL);
        if (!st)
                return error(_("cannot stream blob %s"), oid_to_hex(oid));
        for (;;) {
index a0bdc2fe3b2e5e3f4feab87e4d5f2c5059437c54..97ea8d60d6187b35de7f5fd6ea8bc5c529679bc3 100644 (file)
@@ -347,12 +347,11 @@ static int write_zip_entry(struct archiver_args *args,
                        method = ZIP_METHOD_DEFLATE;
 
                if (!buffer) {
-                       enum object_type type;
-                       stream = odb_read_stream_open(args->repo->objects, oid,
-                                                     &type, &size, NULL);
+                       stream = odb_read_stream_open(args->repo->objects, oid, NULL);
                        if (!stream)
                                return error(_("cannot stream blob %s"),
                                             oid_to_hex(oid));
+                       size = stream->size;
                        flags |= ZIP_STREAM;
                        out = NULL;
                } else {
index 581023495fdc9cad1a370b7c665fe856c68a7bbc..b01cb77f4a8500d3fdce51f859648c4493ba7e97 100644 (file)
@@ -798,8 +798,6 @@ static int compare_objects(const unsigned char *buf, unsigned long size,
 static int check_collison(struct object_entry *entry)
 {
        struct compare_data data;
-       enum object_type type;
-       unsigned long size;
 
        if (entry->size <= repo_settings_get_big_file_threshold(the_repository) ||
            entry->type != OBJ_BLOB)
@@ -807,11 +805,10 @@ static int check_collison(struct object_entry *entry)
 
        memset(&data, 0, sizeof(data));
        data.entry = entry;
-       data.st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
-                                      &type, &size, NULL);
+       data.st = odb_read_stream_open(the_repository->objects, &entry->idx.oid, NULL);
        if (!data.st)
                return -1;
-       if (size != entry->size || type != entry->type)
+       if (data.st->size != entry->size || data.st->type != entry->type)
                die(_("SHA1 COLLISION FOUND WITH %s !"),
                    oid_to_hex(&entry->idx.oid));
        unpack_data(entry, compare_objects, &data);
index f109e26786e6212034cd7da457fb4baf5351423a..0d1d6995bfc35a40dd35f58cd4ba1498bac1c504 100644 (file)
@@ -521,9 +521,11 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
                    oe_size_greater_than(&to_pack, entry,
                                         repo_settings_get_big_file_threshold(the_repository)) &&
                    (st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
-                                              &type, &size, NULL)) != NULL)
+                                              NULL)) != NULL) {
                        buf = NULL;
-               else {
+                       type = st->type;
+                       size = st->size;
+               } else {
                        buf = odb_read_object(the_repository->objects,
                                              &entry->idx.oid, &type,
                                              &size);
index 9601fdb12dc9a80aa470169f672f06408e629fce..12177a7dd707a8f4efa46834f7e4e0a3ee8ddc4f 100644 (file)
@@ -132,19 +132,17 @@ int check_object_signature(struct repository *r, const struct object_id *oid,
 int stream_object_signature(struct repository *r, const struct object_id *oid)
 {
        struct object_id real_oid;
-       unsigned long size;
-       enum object_type obj_type;
        struct odb_read_stream *st;
        struct git_hash_ctx c;
        char hdr[MAX_HEADER_LEN];
        int hdrlen;
 
-       st = odb_read_stream_open(r->objects, oid, &obj_type, &size, NULL);
+       st = odb_read_stream_open(r->objects, oid, NULL);
        if (!st)
                return -1;
 
        /* Generate the header */
-       hdrlen = format_object_header(hdr, sizeof(hdr), obj_type, size);
+       hdrlen = format_object_header(hdr, sizeof(hdr), st->type, st->size);
 
        /* Sha1.. */
        r->hash_algo->init_fn(&c);
index 7ef58adaa2a09e39e725205f963f2a0a85893221..745cd486fbb33d8405eb28d057e8244d6bfc1bf1 100644 (file)
@@ -214,8 +214,6 @@ ssize_t odb_read_stream_read(struct odb_read_stream *st, void *buf, size_t sz)
 
 struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
                                             const struct object_id *oid,
-                                            enum object_type *type,
-                                            unsigned long *size,
                                             struct stream_filter *filter)
 {
        struct odb_read_stream *st;
@@ -235,8 +233,6 @@ struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
                st = nst;
        }
 
-       *size = st->size;
-       *type = st->type;
        return st;
 }
 
@@ -247,18 +243,16 @@ int odb_stream_blob_to_fd(struct object_database *odb,
                          int can_seek)
 {
        struct odb_read_stream *st;
-       enum object_type type;
-       unsigned long sz;
        ssize_t kept = 0;
        int result = -1;
 
-       st = odb_read_stream_open(odb, oid, &type, &sz, filter);
+       st = odb_read_stream_open(odb, oid, filter);
        if (!st) {
                if (filter)
                        free_stream_filter(filter);
                return result;
        }
-       if (type != OBJ_BLOB)
+       if (st->type != OBJ_BLOB)
                goto close_and_exit;
        for (;;) {
                char buf[1024 * 16];
index 7cb55213b780ff4e028fadb6a87cdb2df58d52e7..c7861f7e13c606af66d5b54b52b7b1cc3eb9adad 100644 (file)
@@ -25,16 +25,13 @@ struct odb_read_stream {
 };
 
 /*
- * Create a new object stream for the given object database. Populates the type
- * and size pointers with the object's info. An optional filter can be used to
- * transform the object's content.
+ * Create a new object stream for the given object database. An optional filter
+ * can be used to transform the object's content.
  *
  * Returns the stream on success, a `NULL` pointer otherwise.
  */
 struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
                                             const struct object_id *oid,
-                                            enum object_type *type,
-                                            unsigned long *size,
                                             struct stream_filter *filter);
 
 /*