streaming.c: stop passing around "object_info *" to open()

Change the streaming interface to stop passing around the "struct object_info" the open() functions. As seen in 7ef2d9a2604 (streaming: read non-delta incrementally from a pack, 2011-05-13) which introduced the "st->u.in_pack" assignments being changed here only the open_istream_pack_non_delta() path need these. So let's instead do this when preparing the selected callback in the istream_source() function. This might also allow the compiler to reduce the lifetime of the "oi" variable, as we've moved it from "git_istream()" to "istream_source()". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed May 5, 2021 at 14:33 UTC de94c0eace41c9d93f6c2c97e98797afabb5932e
1 file changed +20 -22
streaming.c
+20 -22
@@ -10,7 +10,6 @@
10
11 typedef int (*open_istream_fn)(struct git_istream *,
12 struct repository *,
13 - struct object_info *,
13 const struct object_id *,
14 enum object_type *);
15 typedef int (*close_istream_fn)(struct git_istream *);
@@ -232,7 +231,6 @@ static struct stream_vtbl loose_vtbl = {
231 };
232
233 static int open_istream_loose(struct git_istream *st, struct repository *r,
235 - struct object_info *oi,
234 const struct object_id *oid,
235 enum object_type *type)
236 {
@@ -337,15 +335,12 @@ static struct stream_vtbl pack_non_delta_vtbl = {
335
336 static int open_istream_pack_non_delta(struct git_istream *st,
337 struct repository *r,
340 - struct object_info *oi,
338 const struct object_id *oid,
339 enum object_type *type)
340 {
341 struct pack_window *window;
342 enum object_type in_pack_type;
343
347 - st->u.in_pack.pack = oi->u.packed.pack;
348 - st->u.in_pack.pos = oi->u.packed.offset;
344 window = NULL;
345
346 in_pack_type = unpack_object_header(st->u.in_pack.pack,
@@ -400,8 +395,7 @@ static struct stream_vtbl incore_vtbl = {
395 };
396
397 static int open_istream_incore(struct git_istream *st, struct repository *r,
403 - struct object_info *oi, const struct object_id *oid,
404 - enum object_type *type)
398 + const struct object_id *oid, enum object_type *type)
399 {
400 st->u.incore.buf = read_object_file_extended(r, oid, type, &st->size, 0);
401 st->u.incore.read_ptr = 0;
@@ -414,26 +408,30 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
408 * static helpers variables and functions for users of streaming interface
409 *****************************************************************************/
410
417 -static open_istream_fn istream_source(struct repository *r,
411 +static open_istream_fn istream_source(struct git_istream *st,
412 + struct repository *r,
413 const struct object_id *oid,
419 - enum object_type *type,
420 - struct object_info *oi)
414 + enum object_type *type)
415 {
416 unsigned long size;
417 int status;
418 + struct object_info oi = OBJECT_INFO_INIT;
419
425 - oi->typep = type;
426 - oi->sizep = &size;
427 - status = oid_object_info_extended(r, oid, oi, 0);
420 + oi.typep = type;
421 + oi.sizep = &size;
422 + status = oid_object_info_extended(r, oid, &oi, 0);
423 if (status < 0)
424 return NULL;
425
431 - switch (oi->whence) {
426 + switch (oi.whence) {
427 case OI_LOOSE:
428 return open_istream_loose;
429 case OI_PACKED:
435 - if (!oi->u.packed.is_delta && big_file_threshold < size)
430 + if (!oi.u.packed.is_delta && big_file_threshold < size) {
431 + st->u.in_pack.pack = oi.u.packed.pack;
432 + st->u.in_pack.pos = oi.u.packed.offset;
433 return open_istream_pack_non_delta;
434 + }
435 /* fallthru */
436 default:
437 return open_istream_incore;
@@ -462,17 +460,17 @@ struct git_istream *open_istream(struct repository *r,
460 unsigned long *size,
461 struct stream_filter *filter)
462 {
465 - struct git_istream *st;
466 - struct object_info oi = OBJECT_INFO_INIT;
463 + struct git_istream *st = xmalloc(sizeof(*st));
464 const struct object_id *real = lookup_replace_object(r, oid);
468 - open_istream_fn open_fn = istream_source(r, real, type, &oi);
465 + open_istream_fn open_fn = istream_source(st, r, real, type);
466
470 - if (!open_fn)
467 + if (!open_fn) {
468 + free(st);
469 return NULL;
470 + }
471
473 - st = xmalloc(sizeof(*st));
474 - if (open_fn(st, r, &oi, real, type)) {
475 - if (open_istream_incore(st, r, &oi, real, type)) {
472 + if (open_fn(st, r, real, type)) {
473 + if (open_istream_incore(st, r, real, type)) {
474 free(st);
475 return NULL;
476 }