Skip to content

Commit 41b42e3

Browse files
pks-tgitster
authored andcommitted
packfile: expose function to read object stream for an offset
The function `packfile_store_read_object_stream()` takes as input an object ID and then constructs a `struct odb_read_stream` from it. In a subsequent commit we'll want to create an object stream for a given combination of packfile and offset though, which is not something that can currently be done. Extract a new function `packfile_read_object_stream()` that makes this functionality available. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 10a6762 commit 41b42e3

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

packfile.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,32 +2553,28 @@ static int close_istream_pack_non_delta(struct odb_read_stream *_st)
25532553
return 0;
25542554
}
25552555

2556-
int packfile_store_read_object_stream(struct odb_read_stream **out,
2557-
struct packfile_store *store,
2558-
const struct object_id *oid)
2556+
int packfile_read_object_stream(struct odb_read_stream **out,
2557+
const struct object_id *oid,
2558+
struct packed_git *pack,
2559+
off_t offset)
25592560
{
25602561
struct odb_packed_read_stream *stream;
25612562
struct pack_window *window = NULL;
2562-
struct object_info oi = OBJECT_INFO_INIT;
25632563
enum object_type in_pack_type;
25642564
unsigned long size;
25652565

2566-
oi.sizep = &size;
2566+
in_pack_type = unpack_object_header(pack, &window, &offset, &size);
2567+
unuse_pack(&window);
25672568

2568-
if (packfile_store_read_object_info(store, oid, &oi, 0) ||
2569-
oi.u.packed.type == PACKED_OBJECT_TYPE_REF_DELTA ||
2570-
oi.u.packed.type == PACKED_OBJECT_TYPE_OFS_DELTA ||
2571-
repo_settings_get_big_file_threshold(store->source->odb->repo) >= size)
2569+
if (repo_settings_get_big_file_threshold(pack->repo) >= size)
25722570
return -1;
25732571

2574-
in_pack_type = unpack_object_header(oi.u.packed.pack,
2575-
&window,
2576-
&oi.u.packed.offset,
2577-
&size);
2578-
unuse_pack(&window);
25792572
switch (in_pack_type) {
25802573
default:
25812574
return -1; /* we do not do deltas for now */
2575+
case OBJ_BAD:
2576+
mark_bad_packed_object(pack, oid);
2577+
return -1;
25822578
case OBJ_COMMIT:
25832579
case OBJ_TREE:
25842580
case OBJ_BLOB:
@@ -2592,10 +2588,22 @@ int packfile_store_read_object_stream(struct odb_read_stream **out,
25922588
stream->base.type = in_pack_type;
25932589
stream->base.size = size;
25942590
stream->z_state = ODB_PACKED_READ_STREAM_UNINITIALIZED;
2595-
stream->pack = oi.u.packed.pack;
2596-
stream->pos = oi.u.packed.offset;
2591+
stream->pack = pack;
2592+
stream->pos = offset;
25972593

25982594
*out = &stream->base;
25992595

26002596
return 0;
26012597
}
2598+
2599+
int packfile_store_read_object_stream(struct odb_read_stream **out,
2600+
struct packfile_store *store,
2601+
const struct object_id *oid)
2602+
{
2603+
struct pack_entry e;
2604+
2605+
if (!find_pack_entry(store, oid, &e))
2606+
return -1;
2607+
2608+
return packfile_read_object_stream(out, oid, e.p, e.offset);
2609+
}

packfile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs,
436436
off_t *curpos, enum object_type type,
437437
off_t delta_obj_offset);
438438

439+
int packfile_read_object_stream(struct odb_read_stream **out,
440+
const struct object_id *oid,
441+
struct packed_git *pack,
442+
off_t offset);
443+
439444
void release_pack_memory(size_t);
440445

441446
/* global flag to enable extra checks when accessing packed objects */

0 commit comments

Comments
 (0)