]> git.ipfire.org Git - thirdparty/git.git/blobdiff - sha1-name.c
sha1-name.c: remove the_repo from get_oid_oneline()
[thirdparty/git.git] / sha1-name.c
index d1cc77c124c11ffd49be472b1368baeda3afbe17..fb80306f1a6aa7b341d8fe0979b7a0401f1cb01f 100644 (file)
 #include "midx.h"
 #include "commit-reach.h"
 
-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);
 
-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
 struct disambiguate_state {
        int len; /* length of prefix in hex chars */
        char hex_pfx[GIT_MAX_HEXSZ + 1];
        struct object_id bin_pfx;
 
+       struct repository *repo;
        disambiguate_hint_fn fn;
        void *cb_data;
        struct object_id candidate;
@@ -38,7 +39,7 @@ struct disambiguate_state {
 static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
 {
        if (ds->always_call_fn) {
-               ds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;
+               ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
                return;
        }
        if (!ds->candidate_exists) {
@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
        }
 
        if (!ds->candidate_checked) {
-               ds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);
+               ds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);
                ds->disambiguate_fn_used = 1;
                ds->candidate_checked = 1;
        }
@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
        }
 
        /* if we reach this point, we know ds->candidate satisfies fn */
-       if (ds->fn(current, ds->cb_data)) {
+       if (ds->fn(ds->repo, current, ds->cb_data)) {
                /*
                 * if both current and candidate satisfy fn, we cannot
                 * disambiguate.
@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
 {
        struct object_directory *odb;
 
-       for (odb = the_repository->objects->odb;
-            odb && !ds->ambiguous;
-            odb = odb->next) {
+       for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {
                int pos;
                struct oid_array *loose_objects;
 
@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)
        struct multi_pack_index *m;
        struct packed_git *p;
 
-       for (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;
+       for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
             m = m->next)
                unique_in_midx(m, ds);
-       for (p = get_packed_git(the_repository); p && !ds->ambiguous;
+       for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
             p = p->next)
                unique_in_pack(p, ds);
 }
@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
                 * same repository!
                 */
                ds->candidate_ok = (!ds->disambiguate_fn_used ||
-                                   ds->fn(&ds->candidate, ds->cb_data));
+                                   ds->fn(ds->repo, &ds->candidate, ds->cb_data));
 
        if (!ds->candidate_ok)
                return SHORT_NAME_AMBIGUOUS;
@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
        return 0;
 }
 
-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_commit_only(struct repository *r,
+                                   const struct object_id *oid,
+                                   void *cb_data_unused)
 {
-       int kind = oid_object_info(the_repository, oid, NULL);
+       int kind = oid_object_info(r, oid, NULL);
        return kind == OBJ_COMMIT;
 }
 
-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_committish_only(struct repository *r,
+                                       const struct object_id *oid,
+                                       void *cb_data_unused)
 {
        struct object *obj;
        int kind;
 
-       kind = oid_object_info(the_repository, oid, NULL);
+       kind = oid_object_info(r, oid, NULL);
        if (kind == OBJ_COMMIT)
                return 1;
        if (kind != OBJ_TAG)
                return 0;
 
        /* We need to do this the hard way... */
-       obj = deref_tag(the_repository, parse_object(the_repository, oid),
-                       NULL, 0);
+       obj = deref_tag(r, parse_object(r, oid), NULL, 0);
        if (obj && obj->type == OBJ_COMMIT)
                return 1;
        return 0;
 }
 
-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_tree_only(struct repository *r,
+                                 const struct object_id *oid,
+                                 void *cb_data_unused)
 {
-       int kind = oid_object_info(the_repository, oid, NULL);
+       int kind = oid_object_info(r, oid, NULL);
        return kind == OBJ_TREE;
 }
 
-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_treeish_only(struct repository *r,
+                                    const struct object_id *oid,
+                                    void *cb_data_unused)
 {
        struct object *obj;
        int kind;
 
-       kind = oid_object_info(the_repository, oid, NULL);
+       kind = oid_object_info(r, oid, NULL);
        if (kind == OBJ_TREE || kind == OBJ_COMMIT)
                return 1;
        if (kind != OBJ_TAG)
                return 0;
 
        /* We need to do this the hard way... */
-       obj = deref_tag(the_repository, parse_object(the_repository, oid),
-                       NULL, 0);
+       obj = deref_tag(r, parse_object(r, oid), NULL, 0);
        if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
                return 1;
        return 0;
 }
 
-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_blob_only(struct repository *r,
+                                 const struct object_id *oid,
+                                 void *cb_data_unused)
 {
-       int kind = oid_object_info(the_repository, oid, NULL);
+       int kind = oid_object_info(r, oid, NULL);
        return kind == OBJ_BLOB;
 }
 
@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)
        return error("unknown hint type for '%s': %s", var, value);
 }
 
-static int init_object_disambiguation(const char *name, int len,
+static int init_object_disambiguation(struct repository *r,
+                                     const char *name, int len,
                                      struct disambiguate_state *ds)
 {
        int i;
@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,
 
        ds->len = len;
        ds->hex_pfx[len] = '\0';
-       prepare_alt_odb(the_repository);
+       ds->repo = r;
+       prepare_alt_odb(r);
        return 0;
 }
 
@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
        struct strbuf desc = STRBUF_INIT;
        int type;
 
-       if (ds->fn && !ds->fn(oid, ds->cb_data))
+       if (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))
                return 0;
 
-       type = oid_object_info(the_repository, oid, NULL);
+       type = oid_object_info(ds->repo, oid, NULL);
        if (type == OBJ_COMMIT) {
-               struct commit *commit = lookup_commit(the_repository, oid);
+               struct commit *commit = lookup_commit(ds->repo, oid);
                if (commit) {
                        struct pretty_print_context pp = {0};
                        pp.date_mode.type = DATE_SHORT;
                        format_commit_message(commit, " %ad - %s", &desc, &pp);
                }
        } else if (type == OBJ_TAG) {
-               struct tag *tag = lookup_tag(the_repository, oid);
+               struct tag *tag = lookup_tag(ds->repo, oid);
                if (!parse_tag(tag) && tag->tag)
                        strbuf_addf(&desc, " %s", tag->tag);
        }
 
        advise("  %s %s%s",
-              find_unique_abbrev(oid, DEFAULT_ABBREV),
+              repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),
               type_name(type) ? type_name(type) : "unknown type",
               desc.buf);
 
@@ -383,10 +392,18 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
        return 0;
 }
 
+static int repo_collect_ambiguous(struct repository *r,
+                                 const struct object_id *oid,
+                                 void *data)
+{
+       return collect_ambiguous(oid, data);
+}
+
+static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
-       int a_type = oid_object_info(the_repository, a, NULL);
-       int b_type = oid_object_info(the_repository, b, NULL);
+       int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
+       int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
        int a_type_sort;
        int b_type_sort;
 
@@ -411,7 +428,16 @@ static int sort_ambiguous(const void *a, const void *b)
        return a_type_sort > b_type_sort ? 1 : -1;
 }
 
-static enum get_oid_result get_short_oid(const char *name, int len,
+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
+{
+       /* mutex will be needed if this code is to be made thread safe */
+       sort_ambiguous_repo = r;
+       QSORT(a->oid, a->nr, sort_ambiguous);
+       sort_ambiguous_repo = NULL;
+}
+
+static enum get_oid_result get_short_oid(struct repository *r,
+                                        const char *name, int len,
                                         struct object_id *oid,
                                         unsigned flags)
 {
@@ -419,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
        struct disambiguate_state ds;
        int quietly = !!(flags & GET_OID_QUIETLY);
 
-       if (init_object_disambiguation(name, len, &ds) < 0)
+       if (init_object_disambiguation(r, name, len, &ds) < 0)
                return -1;
 
        if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -457,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,
                        ds.fn = NULL;
 
                advise(_("The candidates are:"));
-               for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-               QSORT(collect.oid, collect.nr, sort_ambiguous);
+               repo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);
+               sort_ambiguous_oid_array(r, &collect);
 
                if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
                        BUG("show_ambiguous_object shouldn't return non-zero");
@@ -468,17 +494,18 @@ static enum get_oid_result get_short_oid(const char *name, int len,
        return status;
 }
 
-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
+int repo_for_each_abbrev(struct repository *r, const char *prefix,
+                        each_abbrev_fn fn, void *cb_data)
 {
        struct oid_array collect = OID_ARRAY_INIT;
        struct disambiguate_state ds;
        int ret;
 
-       if (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)
+       if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)
                return -1;
 
        ds.always_call_fn = 1;
-       ds.fn = collect_ambiguous;
+       ds.fn = repo_collect_ambiguous;
        ds.cb_data = &collect;
        find_short_object_filename(&ds);
        find_short_packed_object(&ds);
@@ -505,6 +532,7 @@ struct min_abbrev_data {
        unsigned int init_len;
        unsigned int cur_len;
        char *hex;
+       struct repository *repo;
        const struct object_id *oid;
 };
 
@@ -533,6 +561,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
        return 0;
 }
 
+static int repo_extend_abbrev_len(struct repository *r,
+                                 const struct object_id *oid,
+                                 void *cb_data)
+{
+       return extend_abbrev_len(oid, cb_data);
+}
+
 static void find_abbrev_len_for_midx(struct multi_pack_index *m,
                                     struct min_abbrev_data *mad)
 {
@@ -610,21 +645,22 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
        struct multi_pack_index *m;
        struct packed_git *p;
 
-       for (m = get_multi_pack_index(the_repository); m; m = m->next)
+       for (m = get_multi_pack_index(mad->repo); m; m = m->next)
                find_abbrev_len_for_midx(m, mad);
-       for (p = get_packed_git(the_repository); p; p = p->next)
+       for (p = get_packed_git(mad->repo); p; p = p->next)
                find_abbrev_len_for_pack(p, mad);
 }
 
-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex,
+                             const struct object_id *oid, int len)
 {
        struct disambiguate_state ds;
        struct min_abbrev_data mad;
        struct object_id oid_ret;
-       const unsigned hexsz = the_hash_algo->hexsz;
+       const unsigned hexsz = r->hash_algo->hexsz;
 
        if (len < 0) {
-               unsigned long count = approximate_object_count();
+               unsigned long count = repo_approximate_object_count(r);
                /*
                 * Add one because the MSB only tells us the highest bit set,
                 * not including the value of all the _other_ bits (so "15"
@@ -649,6 +685,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
        if (len == hexsz || !len)
                return hexsz;
 
+       mad.repo = r;
        mad.init_len = len;
        mad.cur_len = len;
        mad.hex = hex;
@@ -656,10 +693,10 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 
        find_abbrev_len_packed(&mad);
 
-       if (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)
+       if (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)
                return -1;
 
-       ds.fn = extend_abbrev_len;
+       ds.fn = repo_extend_abbrev_len;
        ds.always_call_fn = 1;
        ds.cb_data = (void *)&mad;
 
@@ -670,13 +707,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
        return mad.cur_len;
 }
 
-const char *find_unique_abbrev(const struct object_id *oid, int len)
+const char *repo_find_unique_abbrev(struct repository *r,
+                                   const struct object_id *oid,
+                                   int len)
 {
        static int bufno;
        static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
        char *hex = hexbuffer[bufno];
        bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
-       find_unique_abbrev_r(hex, oid, len);
+       repo_find_unique_abbrev_r(r, hex, oid, len);
        return hex;
 }
 
@@ -732,7 +771,7 @@ static inline int push_mark(const char *string, int len)
 }
 
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(const char *str, int len, struct object_id *oid,
                          unsigned int flags)
@@ -796,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
                struct strbuf buf = STRBUF_INIT;
                int detached;
 
-               if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
+               if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
                        detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
                        strbuf_release(&buf);
                        if (detached)
@@ -817,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
        if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
            (refs_found > 1 ||
-            !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))
+            !get_short_oid(the_repository,
+                           str, len, &tmp_oid, GET_OID_QUIETLY)))
                warning(warn_msg, len, str);
 
        if (reflog_len) {
@@ -849,7 +889,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
                                return -1;
                        }
                }
-               if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
+               if (read_ref_at(get_main_ref_store(the_repository),
+                               real_ref, flags, at_time, nth, oid, NULL,
                                &co_time, &co_tz, &co_cnt)) {
                        if (!len) {
                                if (starts_with(real_ref, "refs/heads/")) {
@@ -1049,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
                prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
                commit_list_insert((struct commit *)o, &list);
-               ret = get_oid_oneline(prefix, oid, list);
+               ret = get_oid_oneline(the_repository, prefix, oid, list);
                free(prefix);
                return ret;
        }
@@ -1070,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
                        if (ch == 'g' && cp[-1] == '-') {
                                cp++;
                                len -= cp - name;
-                               return get_short_oid(cp, len, oid, flags);
+                               return get_short_oid(the_repository,
+                                                    cp, len, oid, flags);
                        }
                }
        }
@@ -1124,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
        if (!ret)
                return FOUND;
 
-       return get_short_oid(name, len, oid, lookup_flags);
+       return get_short_oid(the_repository, name, len, oid, lookup_flags);
 }
 
 /*
@@ -1162,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
        return 0;
 }
 
-static int get_oid_oneline(const char *prefix, struct object_id *oid,
-                           struct commit_list *list)
+static int get_oid_oneline(struct repository *r,
+                          const char *prefix, struct object_id *oid,
+                          struct commit_list *list)
 {
        struct commit_list *backup = NULL, *l;
        int found = 0;
@@ -1194,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,
                int matches;
 
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-               if (!parse_object(the_repository, &commit->object.oid))
+               if (!parse_object(r, &commit->object.oid))
                        continue;
                buf = get_commit_buffer(commit, NULL);
                p = strstr(buf, "\n\n");
@@ -1246,7 +1289,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid
  * Parse @{-N} syntax, return the number of characters parsed
  * if successful; otherwise signal an error with negative value.
  */
-static int interpret_nth_prior_checkout(const char *name, int namelen,
+static int interpret_nth_prior_checkout(struct repository *r,
+                                       const char *name, int namelen,
                                        struct strbuf *buf)
 {
        long nth;
@@ -1270,12 +1314,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
        cb.remaining = nth;
        strbuf_init(&cb.buf, 20);
 
-       retval = 0;
-       if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
+       retval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),
+                       "HEAD", grab_nth_branch_switch, &cb);
+       if (0 < retval) {
                strbuf_reset(buf);
                strbuf_addbuf(buf, &cb.buf);
                retval = brace - name + 1;
-       }
+       } else
+               retval = 0;
 
        strbuf_release(&cb.buf);
        return retval;
@@ -1345,7 +1391,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
        return 1;
 }
 
-static int reinterpret(const char *name, int namelen, int len,
+static int reinterpret(struct repository *r,
+                      const char *name, int namelen, int len,
                       struct strbuf *buf, unsigned allowed)
 {
        /* we have extra data, which might need further processing */
@@ -1354,7 +1401,7 @@ static int reinterpret(const char *name, int namelen, int len,
        int ret;
 
        strbuf_add(buf, name + len, namelen - len);
-       ret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);
+       ret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);
        /* that data was not interpreted, remove our cruft */
        if (ret < 0) {
                strbuf_setlen(buf, used);
@@ -1367,9 +1414,9 @@ static int reinterpret(const char *name, int namelen, int len,
        return ret - used + len;
 }
 
-static void set_shortened_ref(struct strbuf *buf, const char *ref)
+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)
 {
-       char *s = shorten_unambiguous_ref(ref, 0);
+       char *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);
        strbuf_reset(buf);
        strbuf_addstr(buf, s);
        free(s);
@@ -1390,7 +1437,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)
        return 0;
 }
 
-static int interpret_branch_mark(const char *name, int namelen,
+static int interpret_branch_mark(struct repository *r,
+                                const char *name, int namelen,
                                 int at, struct strbuf *buf,
                                 int (*get_mark)(const char *, int),
                                 const char *(*get_data)(struct branch *,
@@ -1423,12 +1471,14 @@ static int interpret_branch_mark(const char *name, int namelen,
        if (!branch_interpret_allowed(value, allowed))
                return -1;
 
-       set_shortened_ref(buf, value);
+       set_shortened_ref(r, buf, value);
        return len + at;
 }
 
-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,
-                         unsigned allowed)
+int repo_interpret_branch_name(struct repository *r,
+                              const char *name, int namelen,
+                              struct strbuf *buf,
+                              unsigned allowed)
 {
        char *at;
        const char *start;
@@ -1438,14 +1488,14 @@ int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,
                namelen = strlen(name);
 
        if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-               len = interpret_nth_prior_checkout(name, namelen, buf);
+               len = interpret_nth_prior_checkout(r, name, namelen, buf);
                if (!len) {
                        return len; /* syntax Ok, not enough switches */
                } else if (len > 0) {
                        if (len == namelen)
                                return len; /* consumed all */
                        else
-                               return reinterpret(name, namelen, len, buf, allowed);
+                               return reinterpret(r, name, namelen, len, buf, allowed);
                }
        }
 
@@ -1456,17 +1506,17 @@ int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,
                if (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {
                        len = interpret_empty_at(name, namelen, at - name, buf);
                        if (len > 0)
-                               return reinterpret(name, namelen, len, buf,
+                               return reinterpret(r, name, namelen, len, buf,
                                                   allowed);
                }
 
-               len = interpret_branch_mark(name, namelen, at - name, buf,
+               len = interpret_branch_mark(r, name, namelen, at - name, buf,
                                            upstream_mark, branch_get_upstream,
                                            allowed);
                if (len > 0)
                        return len;
 
-               len = interpret_branch_mark(name, namelen, at - name, buf,
+               len = interpret_branch_mark(r, name, namelen, at - name, buf,
                                            push_mark, branch_get_push,
                                            allowed);
                if (len > 0)
@@ -1711,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
                        for_each_ref(handle_one_ref, &list);
                        head_ref(handle_one_ref, &list);
                        commit_list_sort_by_date(&list);
-                       return get_oid_oneline(name + 2, oid, list);
+                       return get_oid_oneline(repo, name + 2, oid, list);
                }
                if (namelen < 3 ||
                    name[2] != ':' ||
@@ -1820,9 +1870,11 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
                               prefix, &oid, &oc);
 }
 
-int get_oid_with_context(struct repository *repo, const char *str,
-                        unsigned flags, struct object_id *oid,
-                        struct object_context *oc)
+enum get_oid_result get_oid_with_context(struct repository *repo,
+                                        const char *str,
+                                        unsigned flags,
+                                        struct object_id *oid,
+                                        struct object_context *oc)
 {
        if (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE)
                BUG("incompatible flags for get_sha1_with_context");