[PATCH 1/8] object-file: always set OI_LOOSE when reading object info
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Dec 18, 2025, 06:28 UTC
- Message-ID
- <20251218-b4-pks-odb-read-object-info-improvements-v1-1-81c8368492be@pks.im>
- In-Reply-To
- <20251218-b4-pks-odb-read-object-info-improvements-v1-0-81c8368492be@pks.im>
There are some early returns in ``odb_source_loose_read_object_info()` in cases where we don't have to open the loose object. These return paths do not set `struct object_info::whence` to `OI_LOOSE` though, so it becomes impossible for the caller to tell the format of such an object.
Nobody seems to care about this right now, but it's a bug waiting to happen. Fix this by always setting `whence` on success.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- object-file.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/object-file.c b/object-file.c index af1c3f972d..716b325669 100644 --- a/object-file.c +++ b/object-file.c @@ -439,12 +439,21 @@ int odb_source_loose_read_object_info(struct odb_source *source, */ if (!oi->typep && !oi->sizep && !oi->contentp) { struct stat st; - if (!oi->disk_sizep && (flags & OBJECT_INFO_QUICK)) - return quick_has_loose(source->loose, oid) ? 0 : -1; + + if (!oi->disk_sizep && (flags & OBJECT_INFO_QUICK)) { + status = quick_has_loose(source->loose, oid) ? 0 : -1; + if (!status) + oi->whence = OI_LOOSE; + return status; + } + if (stat_loose_object(source->loose, oid, &st, &path) < 0) return -1; + if (oi->disk_sizep) *oi->disk_sizep = st.st_size; + + oi->whence = OI_LOOSE; return 0; }
-- 2.52.0.351.gbe84eed79e.dirty