Re: [PATCH v2 08/14] object-name: backend-generic `get_short_oid()`
- From
Toon Claes <toon@iotcl.com>
- Date
- Mar 30, 2026, 15:12 UTC
- Message-ID
- <87cy0lmjwd.fsf@toon--20250203-5JQV3.mail-host-address-is-not-set>
- In-Reply-To
- <20260320-b4-pks-odb-source-abbrev-v2-8-fe65dcd8c735@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 44 quoted lines
> The function `get_short_oid()` takes as input an abbreviated object ID
> and tries to turn that object ID into the full object ID. This is done
> by iterating through all objects that have the user-provided prefix. If
> that yields exactly one object we know that the abbreviated object ID is
> unambiguous, otherwise it is ambiguous and we print the list of objects
> that match the prefix.
>
> We iterate through all objects with the given prefix by calling both
> `find_short_packed_object()` and `find_short_object_filename()`, which
> is of course specific to the "files" backend. But we now have a generic
> way to iterate through objects with a specific prefix.
>
> Refactor the code to use `odb_for_each_object()` instead so that it
> works with object backends different than the "files" backend.
>
> Remove the now-unused `find_short_packed_object()` function.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> object-name.c | 32 ++++++--------------------------
> 1 file changed, 6 insertions(+), 26 deletions(-)
>
> diff --git a/object-name.c b/object-name.c
> index 4c3ace150e..7a224ab4af 100644
> --- a/object-name.c
> +++ b/object-name.c
>
> [snip]
>
> @@ -499,6 +477,7 @@ static enum get_oid_result get_short_oid(struct repository *r,
> struct object_id *oid,
> unsigned flags)
> {
> + struct odb_for_each_object_options opts = { 0 };
> int status;
> struct disambiguate_state ds;
> int quietly = !!(flags & GET_OID_QUIETLY);
> @@ -526,8 +505,10 @@ static enum get_oid_result get_short_oid(struct repository *r,
> else
> ds.fn = default_disambiguate_hint;
>
> - find_short_object_filename(&ds);
> - find_short_packed_object(&ds);
> + opts.prefix = &ds.bin_pfx;This `ds` is initialized by init_object_disambiguation(), which calls parse_oid_prefix() already. That's nice to see!
-- Cheers, Toon