8
#include "replace-object.h"
9
#include "packfile.h"
10
11
-enum input_source {
12
- stream_error = -1,
13
- incore = 0,
14
- loose = 1,
15
- pack_non_delta = 2
16
-};
17
-
11
typedef int (*open_istream_fn)(struct git_istream *,
12
struct repository *,
13
struct object_info *,
417
* static helpers variables and functions for users of streaming interface
418
*****************************************************************************/
419
427
-static open_istream_fn open_istream_tbl[] = {
428
- open_istream_incore,
429
- open_istream_loose,
430
- open_istream_pack_non_delta,
431
-};
432
-
433
-static enum input_source istream_source(struct repository *r,
434
- const struct object_id *oid,
435
- enum object_type *type,
436
- struct object_info *oi)
420
+static open_istream_fn istream_source(struct repository *r,
421
+ const struct object_id *oid,
422
+ enum object_type *type,
423
+ struct object_info *oi)
424
{
425
unsigned long size;
426
int status;
429
oi->sizep = &size;
430
status = oid_object_info_extended(r, oid, oi, 0);
431
if (status < 0)
445
- return stream_error;
432
+ return NULL;
433
434
switch (oi->whence) {
435
case OI_LOOSE:
449
- return loose;
436
+ return open_istream_loose;
437
case OI_PACKED:
438
if (!oi->u.packed.is_delta && big_file_threshold < size)
452
- return pack_non_delta;
439
+ return open_istream_pack_non_delta;
440
/* fallthru */
441
default:
455
- return incore;
442
+ return open_istream_incore;
443
}
444
}
445
459
-
446
/****************************************************************
447
* Users of streaming interface
448
****************************************************************/
468
struct git_istream *st;
469
struct object_info oi = OBJECT_INFO_INIT;
470
const struct object_id *real = lookup_replace_object(r, oid);
485
- enum input_source src = istream_source(r, real, type, &oi);
471
+ open_istream_fn open_fn = istream_source(r, real, type, &oi);
472
487
- if (src < 0)
473
+ if (!open_fn)
474
return NULL;
475
476
st = xmalloc(sizeof(*st));
491
- if (open_istream_tbl[src](st, r, &oi, real, type)) {
477
+ if (open_fn(st, r, &oi, real, type)) {
478
if (open_istream_incore(st, r, &oi, real, type)) {
479
free(st);
480
return NULL;