Skip to content

Commit de94c0e

Browse files
avargitster
authored andcommitted
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 7ef2d9a (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc062ad commit de94c0e

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

streaming.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
typedef int (*open_istream_fn)(struct git_istream *,
1212
struct repository *,
13-
struct object_info *,
1413
const struct object_id *,
1514
enum object_type *);
1615
typedef int (*close_istream_fn)(struct git_istream *);
@@ -232,7 +231,6 @@ static struct stream_vtbl loose_vtbl = {
232231
};
233232

234233
static int open_istream_loose(struct git_istream *st, struct repository *r,
235-
struct object_info *oi,
236234
const struct object_id *oid,
237235
enum object_type *type)
238236
{
@@ -337,15 +335,12 @@ static struct stream_vtbl pack_non_delta_vtbl = {
337335

338336
static int open_istream_pack_non_delta(struct git_istream *st,
339337
struct repository *r,
340-
struct object_info *oi,
341338
const struct object_id *oid,
342339
enum object_type *type)
343340
{
344341
struct pack_window *window;
345342
enum object_type in_pack_type;
346343

347-
st->u.in_pack.pack = oi->u.packed.pack;
348-
st->u.in_pack.pos = oi->u.packed.offset;
349344
window = NULL;
350345

351346
in_pack_type = unpack_object_header(st->u.in_pack.pack,
@@ -400,8 +395,7 @@ static struct stream_vtbl incore_vtbl = {
400395
};
401396

402397
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)
405399
{
406400
st->u.incore.buf = read_object_file_extended(r, oid, type, &st->size, 0);
407401
st->u.incore.read_ptr = 0;
@@ -414,26 +408,30 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
414408
* static helpers variables and functions for users of streaming interface
415409
*****************************************************************************/
416410

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,
418413
const struct object_id *oid,
419-
enum object_type *type,
420-
struct object_info *oi)
414+
enum object_type *type)
421415
{
422416
unsigned long size;
423417
int status;
418+
struct object_info oi = OBJECT_INFO_INIT;
424419

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);
428423
if (status < 0)
429424
return NULL;
430425

431-
switch (oi->whence) {
426+
switch (oi.whence) {
432427
case OI_LOOSE:
433428
return open_istream_loose;
434429
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;
436433
return open_istream_pack_non_delta;
434+
}
437435
/* fallthru */
438436
default:
439437
return open_istream_incore;
@@ -462,17 +460,17 @@ struct git_istream *open_istream(struct repository *r,
462460
unsigned long *size,
463461
struct stream_filter *filter)
464462
{
465-
struct git_istream *st;
466-
struct object_info oi = OBJECT_INFO_INIT;
463+
struct git_istream *st = xmalloc(sizeof(*st));
467464
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);
469466

470-
if (!open_fn)
467+
if (!open_fn) {
468+
free(st);
471469
return NULL;
470+
}
472471

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)) {
476474
free(st);
477475
return NULL;
478476
}

0 commit comments

Comments
 (0)