packfile: thread odb_source_packed through packed_object_info()

Add an optional `struct odb_source_packed *source` parameter to
`packed_object_info()` and `packed_object_info_with_index_pos()`. This
parameter is unused at this point in time, but it will be used in a
follow-up commit so that we can record the source of a specific object.

Note that callers in "odb/source-packed.c" pass the already-available
source, but all other callers pass `NULL` instead. This is fine though,
as we only care about populating this info when called via the packed
store.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
next
Patrick Steinhardt 2026-07-02 14:01:59 +02:00 committed by Junio C Hamano
parent 2ed34f72cf
commit 11c689b873
8 changed files with 17 additions and 13 deletions

View File

@ -497,7 +497,7 @@ static void batch_object_write(const char *obj_name,
data->info.sizep = &data->size;

if (pack)
ret = packed_object_info(pack, offset, &data->info);
ret = packed_object_info(NULL, pack, offset, &data->info);
else
ret = odb_read_object_info_extended(the_repository->objects,
&data->oid, &data->info,

View File

@ -2463,7 +2463,7 @@ static void drop_reused_delta(struct object_entry *entry)

oi.sizep = &size;
oi.typep = &type;
if (packed_object_info(IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
if (packed_object_info(NULL, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
/*
* We failed to get the info from this pack for some reason;
* fall back to odb_read_object_info, which may find another copy.
@ -3804,7 +3804,7 @@ static int add_object_entry_from_pack(const struct object_id *oid,
ofs = nth_packed_object_offset(p, pos);

oi.typep = &type;
if (packed_object_info(p, ofs, &oi) < 0) {
if (packed_object_info(NULL, p, ofs, &oi) < 0) {
die(_("could not get type of object %s in pack %s"),
oid_to_hex(oid), p->pack_name);
} else if (type == OBJ_COMMIT) {

View File

@ -1538,7 +1538,7 @@ static int add_packed_commits(const struct object_id *oid,
struct object_info oi = OBJECT_INFO_INIT;

oi.typep = &type;
if (packed_object_info(pack, offset, &oi) < 0)
if (packed_object_info(NULL, pack, offset, &oi) < 0)
die(_("unable to get type of object %s"), oid_to_hex(oid));

return add_packed_commits_oi(oid, &oi, data);

View File

@ -59,7 +59,7 @@ static int odb_source_packed_read_object_info(struct odb_source *source,
if (!oi)
return 0;

ret = packed_object_info(e.p, e.offset, oi);
ret = packed_object_info(packed, e.p, e.offset, oi);
if (ret < 0) {
mark_bad_packed_object(e.p, oid);
return -1;
@ -99,7 +99,7 @@ static int odb_source_packed_for_each_object_wrapper(const struct object_id *oid
off_t offset = nth_packed_object_offset(pack, index_pos);
struct object_info oi = *data->request;

if (packed_object_info_with_index_pos(pack, offset,
if (packed_object_info_with_index_pos(data->store, pack, offset,
&index_pos, &oi) < 0) {
mark_bad_packed_object(pack, oid);
return -1;

View File

@ -1877,7 +1877,7 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
ofs = pack_pos_to_offset(pack, pos);
}

if (packed_object_info(pack, ofs, &oi) < 0) {
if (packed_object_info(NULL, pack, ofs, &oi) < 0) {
struct object_id oid;
nth_bitmap_object_oid(bitmap_git, &oid,
pack_pos_to_index(pack, pos));

View File

@ -1324,7 +1324,8 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
hashmap_add(&delta_base_cache, &ent->ent);
}

int packed_object_info_with_index_pos(struct packed_git *p, off_t obj_offset,
int packed_object_info_with_index_pos(struct odb_source_packed *source UNUSED,
struct packed_git *p, off_t obj_offset,
uint32_t *maybe_index_pos, struct object_info *oi)
{
struct pack_window *w_curs = NULL;
@ -1446,10 +1447,11 @@ out:
return ret;
}

int packed_object_info(struct packed_git *p, off_t obj_offset,
int packed_object_info(struct odb_source_packed *source,
struct packed_git *p, off_t obj_offset,
struct object_info *oi)
{
return packed_object_info_with_index_pos(p, obj_offset, NULL, oi);
return packed_object_info_with_index_pos(source, p, obj_offset, NULL, oi);
}

static void *unpack_compressed_entry(struct packed_git *p,

View File

@ -320,9 +320,11 @@ extern int do_check_packed_object_crc;
* Look up the object info for a specific offset in the packfile.
* Returns zero on success, a negative error code otherwise.
*/
int packed_object_info(struct packed_git *pack,
int packed_object_info(struct odb_source_packed *source,
struct packed_git *pack,
off_t offset, struct object_info *);
int packed_object_info_with_index_pos(struct packed_git *p, off_t obj_offset,
int packed_object_info_with_index_pos(struct odb_source_packed *source,
struct packed_git *p, off_t obj_offset,
uint32_t *maybe_index_pos, struct object_info *oi);

void mark_bad_packed_object(struct packed_git *, const struct object_id *);

View File

@ -52,7 +52,7 @@ static int add_packed_object(const struct object_id *oid,

entry = packlist_alloc(packed, oid);
entry->idx.offset = nth_packed_object_offset(pack, pos);
if (packed_object_info(pack, entry->idx.offset, &oi) < 0)
if (packed_object_info(NULL, pack, entry->idx.offset, &oi) < 0)
die("could not get type of object %s",
oid_to_hex(oid));
oe_set_type(entry, type);