sha1-name.c: add repo_for_each_abbrev()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 16, 2019 at 16:33 UTC 4e99f2dbea542bc5d7f696f7a358737eb521f040
2 files changed +5 -3
cache.h
+2 -1
@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
1392 struct object_context *oc);
1393
1394 typedef int each_abbrev_fn(const struct object_id *oid, void *);
1395 -extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
1395 +int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
1396 +#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
1397
1398 extern int set_disambiguate_hint_config(const char *var, const char *value);
1399
sha1-name.c
+3 -2
@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,
493 return status;
494 }
495
496 -int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
496 +int repo_for_each_abbrev(struct repository *r, const char *prefix,
497 + each_abbrev_fn fn, void *cb_data)
498 {
499 struct oid_array collect = OID_ARRAY_INIT;
500 struct disambiguate_state ds;
501 int ret;
502
502 - if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
503 + if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)
504 return -1;
505
506 ds.always_call_fn = 1;