aboutsummaryrefslogtreecommitdiffstats
path: root/refs.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-08-17 13:09:55 -0700
committerJunio C Hamano <gitster@pobox.com>2018-08-17 13:09:55 -0700
commit72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0 (patch)
tree3ae354187efd31883707de12020f700e2d128c9e /refs.c
parent60858f343aa909305c28790c7684bf88905695a2 (diff)
parent60650a48c0b24ecf64468426ec13b88c07069b28 (diff)
downloadgit-72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0.tar.gz
Merge branch 'jt/refspec-dwim-precedence-fix'
"git fetch $there refs/heads/s" ought to fetch the tip of the branch 's', but when "refs/heads/refs/heads/s", i.e. a branch whose name is "refs/heads/s" exists at the same time, fetched that one instead by mistake. This has been corrected to honor the usual disambiguation rules for abbreviated refnames. * jt/refspec-dwim-precedence-fix: remote: make refspec follow the same disambiguation rule as local refs
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/refs.c b/refs.c
index 5b412c61ef..de81c7be7c 100644
--- a/refs.c
+++ b/refs.c
@@ -490,16 +490,24 @@ static const char *ref_rev_parse_rules[] = {
NULL
};
+#define NUM_REV_PARSE_RULES (ARRAY_SIZE(ref_rev_parse_rules) - 1)
+
+/*
+ * Is it possible that the caller meant full_name with abbrev_name?
+ * If so return a non-zero value to signal "yes"; the magnitude of
+ * the returned value gives the precedence used for disambiguation.
+ *
+ * If abbrev_name cannot mean full_name, return 0.
+ */
int refname_match(const char *abbrev_name, const char *full_name)
{
const char **p;
const int abbrev_name_len = strlen(abbrev_name);
+ const int num_rules = NUM_REV_PARSE_RULES;
- for (p = ref_rev_parse_rules; *p; p++) {
- if (!strcmp(full_name, mkpath(*p, abbrev_name_len, abbrev_name))) {
- return 1;
- }
- }
+ for (p = ref_rev_parse_rules; *p; p++)
+ if (!strcmp(full_name, mkpath(*p, abbrev_name_len, abbrev_name)))
+ return &ref_rev_parse_rules[num_rules] - p;
return 0;
}