]> git.ipfire.org Git - thirdparty/git.git/commitdiff
streaming: explicitly pass packfile info when streaming a packed object
authorPatrick Steinhardt <ps@pks.im>
Sun, 23 Nov 2025 18:59:29 +0000 (19:59 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 23 Nov 2025 20:56:44 +0000 (12:56 -0800)
When streaming a packed object we first populate the stream with
information about the pack that contains the object before calling
`open_istream_pack_non_delta()`. This is done because we have already
looked up both the pack and the object's offset, so it would be a waste
of time to look up this information again.

But the way this is done makes for a somewhat awkward calling interface,
as the caller now needs to be aware of how exactly the function itself
behaves.

Refactor the code so that we instead explicitly pass the packfile info
into `open_istream_pack_non_delta()`. This makes the calling convention
explicit, but more importantly this allows us to refactor the function
so that it becomes its responsibility to allocate the stream itself in a
subsequent patch.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
streaming.c

index 665624ddc0494e1af2323ea877676cd3155a6d6e..bf277daadd48c20a05072a45deb76beaf0295050 100644 (file)
@@ -340,16 +340,18 @@ static int close_istream_pack_non_delta(struct odb_read_stream *st)
 
 static int open_istream_pack_non_delta(struct odb_read_stream *st,
                                       struct repository *r UNUSED,
-                                      const struct object_id *oid UNUSED)
+                                      const struct object_id *oid UNUSED,
+                                      struct packed_git *pack,
+                                      off_t offset)
 {
        struct pack_window *window;
        enum object_type in_pack_type;
 
        window = NULL;
 
-       in_pack_type = unpack_object_header(st->u.in_pack.pack,
+       in_pack_type = unpack_object_header(pack,
                                            &window,
-                                           &st->u.in_pack.pos,
+                                           &offset,
                                            &st->size);
        unuse_pack(&window);
        switch (in_pack_type) {
@@ -365,6 +367,8 @@ static int open_istream_pack_non_delta(struct odb_read_stream *st,
        st->z_state = z_unused;
        st->close = close_istream_pack_non_delta;
        st->read = read_istream_pack_non_delta;
+       st->u.in_pack.pack = pack;
+       st->u.in_pack.pos = offset;
 
        return 0;
 }
@@ -436,14 +440,10 @@ static int istream_source(struct odb_read_stream *st,
                return 0;
        case OI_PACKED:
                if (oi.u.packed.is_delta ||
-                   repo_settings_get_big_file_threshold(the_repository) >= size)
+                   repo_settings_get_big_file_threshold(the_repository) >= size ||
+                   open_istream_pack_non_delta(st, r, oid, oi.u.packed.pack,
+                                               oi.u.packed.offset) < 0)
                        break;
-
-               st->u.in_pack.pack = oi.u.packed.pack;
-               st->u.in_pack.pos = oi.u.packed.offset;
-               if (open_istream_pack_non_delta(st, r, oid) < 0)
-                       break;
-
                return 0;
        default:
                break;