]> git.ipfire.org Git - thirdparty/git.git/commit
object-file: always set OI_LOOSE when reading object info
authorPatrick Steinhardt <ps@pks.im>
Mon, 12 Jan 2026 09:00:41 +0000 (10:00 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Jan 2026 14:51:14 +0000 (06:51 -0800)
commit123e8186a72cd71863668b6acb23a2faa30e6968
treefc3d73e883d89c8d4a19fa19100f28c4b4516d0a
parent00f117fafea4a43e95425c4abdb8cb58ec8e76b4
object-file: always set OI_LOOSE when reading object info

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.

The root cause of this really is that we have so many different return
paths in the function. As a consequence, it's harder than necessary to
make sure that all successful exit paths sot up the `whence` field as
expected.

Address this by refactoring the function to have a single exit path.
Like this, we can trivially set up the `whence` field when we exit
successfully from the function.

Note that we also:

  - Rename `status` to `ret` to match our usual coding style, but also
    to show that the old `status` variable is now always getting the
    expected value. Furthermore, the value is not initialized anymore,
    which has the consequence that most compilers will warn for exit
    paths where we forgot to set it.

  - Move the setup of scratch pointers closer to `parse_loose_header()`
    to show where it's needed.

  - Guard a couple of variables on cleanup so that they only get
    released in case they have been set up.

  - Reset `oi->delta_base_oid` towards the end of the function, together
    with all the other object info pointers.

Overall, all these changes result in a diff that is somewhat hard to
read. But the end result is significantly easier to read and reason
about, so I'd argue this one-time churn is worth it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c