streaming: explicitly pass packfile info when streaming a packed object

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>

Patrick Steinhardt committed Nov 23, 2025 at 19:59 UTC 3c7722dd4d376e0fce4c48f723fe8b69af785998
1 file changed +10 -10
streaming.c
+10 -10
@@ -340,16 +340,18 @@ static int close_istream_pack_non_delta(struct odb_read_stream *st)
340
341 static int open_istream_pack_non_delta(struct odb_read_stream *st,
342 struct repository *r UNUSED,
343 - const struct object_id *oid UNUSED)
343 + const struct object_id *oid UNUSED,
344 + struct packed_git *pack,
345 + off_t offset)
346 {
347 struct pack_window *window;
348 enum object_type in_pack_type;
349
350 window = NULL;
351
350 - in_pack_type = unpack_object_header(st->u.in_pack.pack,
352 + in_pack_type = unpack_object_header(pack,
353 &window,
352 - &st->u.in_pack.pos,
354 + &offset,
355 &st->size);
356 unuse_pack(&window);
357 switch (in_pack_type) {
@@ -365,6 +367,8 @@ static int open_istream_pack_non_delta(struct odb_read_stream *st,
367 st->z_state = z_unused;
368 st->close = close_istream_pack_non_delta;
369 st->read = read_istream_pack_non_delta;
370 + st->u.in_pack.pack = pack;
371 + st->u.in_pack.pos = offset;
372
373 return 0;
374 }
@@ -436,14 +440,10 @@ static int istream_source(struct odb_read_stream *st,
440 return 0;
441 case OI_PACKED:
442 if (oi.u.packed.is_delta ||
439 - repo_settings_get_big_file_threshold(the_repository) >= size)
443 + repo_settings_get_big_file_threshold(the_repository) >= size ||
444 + open_istream_pack_non_delta(st, r, oid, oi.u.packed.pack,
445 + oi.u.packed.offset) < 0)
446 break;
441 -
442 - st->u.in_pack.pack = oi.u.packed.pack;
443 - st->u.in_pack.pos = oi.u.packed.offset;
444 - if (open_istream_pack_non_delta(st, r, oid) < 0)
445 - break;
446 -
447 return 0;
448 default:
449 break;