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>
Patrick Steinhardt committed
Feb 23, 2026 at 17:00 UTC
41b42e3527eb6b0ab4b557d16adedcd255c9045f
2 files changed
+29
-16
packfile.c
+24
-16
@@ -2553,32 +2553,28 @@ static int close_istream_pack_non_delta(struct odb_read_stream *_st)
2553
return 0;
2554
}
2555
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)
2560
{
2561
struct odb_packed_read_stream *stream;
2562
struct pack_window *window = NULL;
2562
- struct object_info oi = OBJECT_INFO_INIT;
2563
enum object_type in_pack_type;
2564
unsigned long size;
2565
2566
- oi.sizep = &size;
2566
+ in_pack_type = unpack_object_header(pack, &window, &offset, &size);
2567
+ unuse_pack(&window);
2568
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)
2570
return -1;
2571
2574
- in_pack_type = unpack_object_header(oi.u.packed.pack,
2575
- &window,
2576
- &oi.u.packed.offset,
2577
- &size);
2578
- unuse_pack(&window);
2572
switch (in_pack_type) {
2573
default:
2574
return -1; /* we do not do deltas for now */
2575
+ case OBJ_BAD:
2576
+ mark_bad_packed_object(pack, oid);
2577
+ return -1;
2578
case OBJ_COMMIT:
2579
case OBJ_TREE:
2580
case OBJ_BLOB:
@@ -2592,10 +2588,22 @@ int packfile_store_read_object_stream(struct odb_read_stream **out,
2588
stream->base.type = in_pack_type;
2589
stream->base.size = size;
2590
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;
2593
2594
*out = &stream->base;
2595
2596
return 0;
2597
}
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
+5
@@ -436,6 +436,11 @@ off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs,
436
off_t *curpos, enum object_type type,
437
off_t delta_obj_offset);
438
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
+
444
void release_pack_memory(size_t);
445
446
/* global flag to enable extra checks when accessing packed objects */