diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-08-17 22:09:55 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-08-17 22:09:55 +0200 |
commit | 72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0 (patch) | |
tree | 3ae354187efd31883707de12020f700e2d128c9e /refs.c | |
parent | Merge branch 'jk/merge-subtree-heuristics' (diff) | |
parent | remote: make refspec follow the same disambiguation rule as local refs (diff) | |
download | git-72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0.tar.xz git-72c11b7e62c02d18a51f0bbaa2154ecebf8c74f0.zip |
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.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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; } |