]> 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 a75992eb54242e3145392109aee7af68077776ab..fb80306f1a6aa7b341d8fe0979b7a0401f1cb01f 100644 (file)
@@ -15,7 +15,7 @@
 #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)(struct repository *, const struct object_id *, void *);
 
@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
        sort_ambiguous_repo = NULL;
 }
 
-static enum get_oid_result get_short_oid(const char *name, int len,
+static enum get_oid_result get_short_oid(struct repository *r,
+                                        const char *name, int len,
                                         struct object_id *oid,
                                         unsigned flags)
 {
@@ -444,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(the_repository, name, len, &ds) < 0)
+       if (init_object_disambiguation(r, name, len, &ds) < 0)
                return -1;
 
        if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -482,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);
-               sort_ambiguous_oid_array(the_repository, &collect);
+               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");
@@ -493,13 +494,14 @@ 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(the_repository, prefix, strlen(prefix), &ds) < 0)
+       if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)
                return -1;
 
        ds.always_call_fn = 1;
@@ -769,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)
@@ -833,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)
@@ -854,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) {
@@ -1087,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;
        }
@@ -1108,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);
                        }
                }
        }
@@ -1162,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);
 }
 
 /*
@@ -1200,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;
@@ -1232,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");
@@ -1284,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;
@@ -1308,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;
@@ -1383,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 */
@@ -1392,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);
@@ -1405,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);
@@ -1428,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 *,
@@ -1461,7 +1471,7 @@ 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;
 }
 
@@ -1474,20 +1484,18 @@ int repo_interpret_branch_name(struct repository *r,
        const char *start;
        int len;
 
-       if (r != the_repository)
-               BUG("interpret_branch_name() does not really use 'r' yet");
        if (!namelen)
                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);
                }
        }
 
@@ -1498,17 +1506,17 @@ int repo_interpret_branch_name(struct repository *r,
                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)
@@ -1753,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] != ':' ||