Skip to content

Commit 3c7722d

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 3f64dea commit 3c7722d

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

streaming.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,18 @@ static int close_istream_pack_non_delta(struct odb_read_stream *st)
340340

341341
static int open_istream_pack_non_delta(struct odb_read_stream *st,
342342
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)
344346
{
345347
struct pack_window *window;
346348
enum object_type in_pack_type;
347349

348350
window = NULL;
349351

350-
in_pack_type = unpack_object_header(st->u.in_pack.pack,
352+
in_pack_type = unpack_object_header(pack,
351353
&window,
352-
&st->u.in_pack.pos,
354+
&offset,
353355
&st->size);
354356
unuse_pack(&window);
355357
switch (in_pack_type) {
@@ -365,6 +367,8 @@ static int open_istream_pack_non_delta(struct odb_read_stream *st,
365367
st->z_state = z_unused;
366368
st->close = close_istream_pack_non_delta;
367369
st->read = read_istream_pack_non_delta;
370+
st->u.in_pack.pack = pack;
371+
st->u.in_pack.pos = offset;
368372

369373
return 0;
370374
}
@@ -436,14 +440,10 @@ static int istream_source(struct odb_read_stream *st,
436440
return 0;
437441
case OI_PACKED:
438442
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)
440446
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-
447447
return 0;
448448
default:
449449
break;

0 commit comments

Comments
 (0)