aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-20 08:07:33 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-20 13:16:42 -0700
commitd2612fe59e605102cb422fadbb0cb8bea499daee (patch)
treea8e4be33904b445066f7fdf3849401bd89255ca9
parent28c9254e3b3e1304b5a6c36146cf6fec29f3f5d3 (diff)
downloadgit-d2612fe59e605102cb422fadbb0cb8bea499daee.tar.xz
object-name: backend-generic `repo_collect_ambiguous()`
The function `repo_collect_ambiguous()` is responsible for collecting objects whose IDs match a specific prefix. The information is then used to inform the user about which objects they could have meant in case a short object ID is ambiguous. The logic to do this uses the object disambiguation infrastructure and calls into backend-specific functions to iterate through loose and packed objects. This isn't really required anymore though: all we want to do is to enumerate objects that have such a prefix and then append those objects to a `struct oid_array`. This can be trivially achieved in a generic way now that `odb_for_each_object()` has learned to yield only objects that match such a prefix. Refactor the code to use the backend-generic infrastructure instead. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--object-name.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/object-name.c b/object-name.c
index fd1b010ab3..4c3ace150e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -448,8 +448,8 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
return 0;
}
-static int repo_collect_ambiguous(struct repository *r UNUSED,
- const struct object_id *oid,
+static int repo_collect_ambiguous(const struct object_id *oid,
+ struct object_info *oi UNUSED,
void *data)
{
return collect_ambiguous(oid, data);
@@ -586,18 +586,19 @@ int repo_for_each_abbrev(struct repository *r, const char *prefix,
const struct git_hash_algo *algo,
each_abbrev_fn fn, void *cb_data)
{
+ struct object_id prefix_oid = { 0 };
+ struct odb_for_each_object_options opts = {
+ .prefix = &prefix_oid,
+ .prefix_hex_len = strlen(prefix),
+ };
struct oid_array collect = OID_ARRAY_INIT;
- struct disambiguate_state ds;
int ret;
- if (init_object_disambiguation(r, prefix, strlen(prefix), algo, &ds) < 0)
+ if (parse_oid_prefix(prefix, opts.prefix_hex_len, algo, NULL, &prefix_oid) < 0)
return -1;
- ds.always_call_fn = 1;
- ds.fn = repo_collect_ambiguous;
- ds.cb_data = &collect;
- find_short_object_filename(&ds);
- find_short_packed_object(&ds);
+ if (odb_for_each_object_ext(r->objects, NULL, repo_collect_ambiguous, &collect, &opts) < 0)
+ return -1;
ret = oid_array_for_each_unique(&collect, fn, cb_data);
oid_array_clear(&collect);