Skip to content

Commit d2612fe

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 28c9254 commit d2612fe

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

object-name.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
448448
return 0;
449449
}
450450

451-
static int repo_collect_ambiguous(struct repository *r UNUSED,
452-
const struct object_id *oid,
451+
static int repo_collect_ambiguous(const struct object_id *oid,
452+
struct object_info *oi UNUSED,
453453
void *data)
454454
{
455455
return collect_ambiguous(oid, data);
@@ -586,18 +586,19 @@ int repo_for_each_abbrev(struct repository *r, const char *prefix,
586586
const struct git_hash_algo *algo,
587587
each_abbrev_fn fn, void *cb_data)
588588
{
589+
struct object_id prefix_oid = { 0 };
590+
struct odb_for_each_object_options opts = {
591+
.prefix = &prefix_oid,
592+
.prefix_hex_len = strlen(prefix),
593+
};
589594
struct oid_array collect = OID_ARRAY_INIT;
590-
struct disambiguate_state ds;
591595
int ret;
592596

593-
if (init_object_disambiguation(r, prefix, strlen(prefix), algo, &ds) < 0)
597+
if (parse_oid_prefix(prefix, opts.prefix_hex_len, algo, NULL, &prefix_oid) < 0)
594598
return -1;
595599

596-
ds.always_call_fn = 1;
597-
ds.fn = repo_collect_ambiguous;
598-
ds.cb_data = &collect;
599-
find_short_object_filename(&ds);
600-
find_short_packed_object(&ds);
600+
if (odb_for_each_object_ext(r->objects, NULL, repo_collect_ambiguous, &collect, &opts) < 0)
601+
return -1;
601602

602603
ret = oid_array_for_each_unique(&collect, fn, cb_data);
603604
oid_array_clear(&collect);

0 commit comments

Comments
 (0)