Skip to content

Commit 3f64dea

Browse files
pks-tgitster
authored andcommitted
streaming: propagate final object type via the stream
When opening the read stream for a specific object the caller is also expected to pass in a pointer to the object type. This type is passed down via multiple levels and will eventually be populated with the type of the looked-up object. The way we propagate down the pointer though is somewhat non-obvious. While `istream_source()` still expects the pointer and looks it up via `odb_read_object_info_extended()`, we also pass it down even further into the format-specific callbacks that perform another lookup. This is quite confusing overall. Refactor the code so that the responsibility to populate the object type rests solely with the format-specific callbacks. This will allow us to drop the call to `odb_read_object_info_extended()` in `istream_source()` entirely in a subsequent patch. Furthermore, instead of propagating the type via an in-pointer, we now propagate the type via a new field in the object stream. It already has a `size` field, so it's only natural to have a second field that contains the object type. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 70c8b5f commit 3f64dea

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

streaming.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct odb_read_stream {
3333
close_istream_fn close;
3434
read_istream_fn read;
3535

36+
enum object_type type;
3637
unsigned long size; /* inflated size of full object */
3738
git_zstream z;
3839
enum { z_unused, z_used, z_done, z_error } z_state;
@@ -159,6 +160,7 @@ static struct odb_read_stream *attach_stream_filter(struct odb_read_stream *st,
159160
fs->o_end = fs->o_ptr = 0;
160161
fs->input_finished = 0;
161162
ifs->size = -1; /* unknown */
163+
ifs->type = st->type;
162164
return ifs;
163165
}
164166

@@ -221,14 +223,13 @@ static int close_istream_loose(struct odb_read_stream *st)
221223
}
222224

223225
static int open_istream_loose(struct odb_read_stream *st, struct repository *r,
224-
const struct object_id *oid,
225-
enum object_type *type)
226+
const struct object_id *oid)
226227
{
227228
struct object_info oi = OBJECT_INFO_INIT;
228229
struct odb_source *source;
229230

230231
oi.sizep = &st->size;
231-
oi.typep = type;
232+
oi.typep = &st->type;
232233

233234
odb_prepare_alternates(r->objects);
234235
for (source = r->objects->sources; source; source = source->next) {
@@ -249,7 +250,7 @@ static int open_istream_loose(struct odb_read_stream *st, struct repository *r,
249250
case ULHR_TOO_LONG:
250251
goto error;
251252
}
252-
if (parse_loose_header(st->u.loose.hdr, &oi) < 0 || *type < 0)
253+
if (parse_loose_header(st->u.loose.hdr, &oi) < 0 || st->type < 0)
253254
goto error;
254255

255256
st->u.loose.hdr_used = strlen(st->u.loose.hdr) + 1;
@@ -339,8 +340,7 @@ static int close_istream_pack_non_delta(struct odb_read_stream *st)
339340

340341
static int open_istream_pack_non_delta(struct odb_read_stream *st,
341342
struct repository *r UNUSED,
342-
const struct object_id *oid UNUSED,
343-
enum object_type *type UNUSED)
343+
const struct object_id *oid UNUSED)
344344
{
345345
struct pack_window *window;
346346
enum object_type in_pack_type;
@@ -361,6 +361,7 @@ static int open_istream_pack_non_delta(struct odb_read_stream *st,
361361
case OBJ_TAG:
362362
break;
363363
}
364+
st->type = in_pack_type;
364365
st->z_state = z_unused;
365366
st->close = close_istream_pack_non_delta;
366367
st->read = read_istream_pack_non_delta;
@@ -396,15 +397,15 @@ static ssize_t read_istream_incore(struct odb_read_stream *st, char *buf, size_t
396397
}
397398

398399
static int open_istream_incore(struct odb_read_stream *st, struct repository *r,
399-
const struct object_id *oid, enum object_type *type)
400+
const struct object_id *oid)
400401
{
401402
struct object_info oi = OBJECT_INFO_INIT;
402403

403404
st->u.incore.read_ptr = 0;
404405
st->close = close_istream_incore;
405406
st->read = read_istream_incore;
406407

407-
oi.typep = type;
408+
oi.typep = &st->type;
408409
oi.sizep = &st->size;
409410
oi.contentp = (void **)&st->u.incore.buf;
410411
return odb_read_object_info_extended(r->objects, oid, &oi,
@@ -417,22 +418,20 @@ static int open_istream_incore(struct odb_read_stream *st, struct repository *r,
417418

418419
static int istream_source(struct odb_read_stream *st,
419420
struct repository *r,
420-
const struct object_id *oid,
421-
enum object_type *type)
421+
const struct object_id *oid)
422422
{
423423
unsigned long size;
424424
int status;
425425
struct object_info oi = OBJECT_INFO_INIT;
426426

427-
oi.typep = type;
428427
oi.sizep = &size;
429428
status = odb_read_object_info_extended(r->objects, oid, &oi, 0);
430429
if (status < 0)
431430
return status;
432431

433432
switch (oi.whence) {
434433
case OI_LOOSE:
435-
if (open_istream_loose(st, r, oid, type) < 0)
434+
if (open_istream_loose(st, r, oid) < 0)
436435
break;
437436
return 0;
438437
case OI_PACKED:
@@ -442,15 +441,15 @@ static int istream_source(struct odb_read_stream *st,
442441

443442
st->u.in_pack.pack = oi.u.packed.pack;
444443
st->u.in_pack.pos = oi.u.packed.offset;
445-
if (open_istream_pack_non_delta(st, r, oid, type) < 0)
444+
if (open_istream_pack_non_delta(st, r, oid) < 0)
446445
break;
447446

448447
return 0;
449448
default:
450449
break;
451450
}
452451

453-
return open_istream_incore(st, r, oid, type);
452+
return open_istream_incore(st, r, oid);
454453
}
455454

456455
/****************************************************************
@@ -477,7 +476,7 @@ struct odb_read_stream *open_istream(struct repository *r,
477476
{
478477
struct odb_read_stream *st = xmalloc(sizeof(*st));
479478
const struct object_id *real = lookup_replace_object(r, oid);
480-
int ret = istream_source(st, r, real, type);
479+
int ret = istream_source(st, r, real);
481480

482481
if (ret) {
483482
free(st);
@@ -495,6 +494,7 @@ struct odb_read_stream *open_istream(struct repository *r,
495494
}
496495

497496
*size = st->size;
497+
*type = st->type;
498498
return st;
499499
}
500500

0 commit comments

Comments
 (0)