From: Patrick Steinhardt Date: Thu, 18 Dec 2025 06:28:14 GMT Subject: [PATCH 4/8] packfile: always populate pack-specific info when reading object info Message-ID: <20251218-b4-pks-odb-read-object-info-improvements-v1-4-81c8368492be@pks.im> In-Reply-To: <20251218-b4-pks-odb-read-object-info-improvements-v1-0-81c8368492be@pks.im> When reading object information from a packfile we are not always populating the pack-specific information. This happens in two cases: - When calling `packed_object_info()` directly instead of `packfile_store_read_object_info()`. - When we've got the empty request. Fix both of these issues so that we can always assume the pack info to be populated when reading object info from a pack. Note that we don't really care about the second case right now, as the condition will always evaluate to false anyway. This will be fixed in the next commit. Signed-off-by: Patrick Steinhardt --- packfile.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/packfile.c b/packfile.c index 9bce52f912..6e66c90c46 100644 --- a/packfile.c +++ b/packfile.c @@ -1657,6 +1657,20 @@ int packed_object_info(struct repository *r, struct packed_git *p, } oi->whence = OI_PACKED; + oi->u.packed.offset = obj_offset; + oi->u.packed.pack = p; + + switch (type) { + case OBJ_REF_DELTA: + oi->u.packed.type = PACKED_OBJECT_TYPE_REF_DELTA; + break; + case OBJ_OFS_DELTA: + oi->u.packed.type = PACKED_OBJECT_TYPE_OFS_DELTA; + break; + default: + oi->u.packed.type = PACKED_OBJECT_TYPE_FULL; + break; + } out: unuse_pack(&w_curs); @@ -2148,8 +2162,13 @@ int packfile_store_read_object_info(struct packfile_store *store, * We know that the caller doesn't actually need the * information below, so return early. */ - if (oi == &blank_oi) + if (oi == &blank_oi) { + oi->whence = OI_PACKED; + oi->u.packed.offset = e.offset; + oi->u.packed.pack = e.p; + oi->u.packed.type = PACKED_OBJECT_TYPE_UNKNOWN; return 0; + } rtype = packed_object_info(store->odb->repo, e.p, e.offset, oi); if (rtype < 0) { @@ -2157,23 +2176,6 @@ int packfile_store_read_object_info(struct packfile_store *store, return -1; } - if (oi->whence == OI_PACKED) { - oi->u.packed.offset = e.offset; - oi->u.packed.pack = e.p; - - switch (rtype) { - case OBJ_REF_DELTA: - oi->u.packed.type = PACKED_OBJECT_TYPE_REF_DELTA; - break; - case OBJ_OFS_DELTA: - oi->u.packed.type = PACKED_OBJECT_TYPE_OFS_DELTA; - break; - default: - oi->u.packed.type = PACKED_OBJECT_TYPE_FULL; - break; - } - } - return 0; } -- 2.52.0.351.gbe84eed79e.dirty