summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorBert Wesarg <bert.wesarg@googlemail.com>2009-04-13 12:25:46 +0200
committerJunio C Hamano <gitster@pobox.com>2009-04-13 09:36:44 -0700
commit6e7b3309d356077337b8222683a743c27fa7276c (patch)
tree64b2fc3c755697457c22b3eb5b121707a16c395b /refs.c
parentf800b65bea1504299747e7be03ee279508a74e1f (diff)
downloadgit-6e7b3309d356077337b8222683a743c27fa7276c.tar.gz
shorten_unambiguous_ref(): add strict mode
Add the strict mode of abbreviation to shorten_unambiguous_ref(), i.e. the resulting ref won't trigger the ambiguous ref warning. All users of shorten_unambiguous_ref() still use the loose mode. Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/refs.c b/refs.c
index 82afb87684..e65a3b4c4e 100644
--- a/refs.c
+++ b/refs.c
@@ -1681,7 +1681,7 @@ static void gen_scanf_fmt(char *scanf_fmt, const char *rule)
return;
}
-char *shorten_unambiguous_ref(const char *ref)
+char *shorten_unambiguous_ref(const char *ref, int strict)
{
int i;
static char **scanf_fmts;
@@ -1718,6 +1718,7 @@ char *shorten_unambiguous_ref(const char *ref)
/* skip first rule, it will always match */
for (i = nr_rules - 1; i > 0 ; --i) {
int j;
+ int rules_to_fail = i;
int short_name_len;
if (1 != sscanf(ref, scanf_fmts[i], short_name))
@@ -1726,14 +1727,25 @@ char *shorten_unambiguous_ref(const char *ref)
short_name_len = strlen(short_name);
/*
+ * in strict mode, all (except the matched one) rules
+ * must fail to resolve to a valid non-ambiguous ref
+ */
+ if (strict)
+ rules_to_fail = nr_rules;
+
+ /*
* check if the short name resolves to a valid ref,
* but use only rules prior to the matched one
*/
- for (j = 0; j < i; j++) {
+ for (j = 0; j < rules_to_fail; j++) {
const char *rule = ref_rev_parse_rules[j];
unsigned char short_objectname[20];
char refname[PATH_MAX];
+ /* skip matched rule */
+ if (i == j)
+ continue;
+
/*
* the short name is ambiguous, if it resolves
* (with this previous rule) to a valid ref
@@ -1749,7 +1761,7 @@ char *shorten_unambiguous_ref(const char *ref)
* short name is non-ambiguous if all previous rules
* haven't resolved to a valid ref
*/
- if (j == i)
+ if (j == rules_to_fail)
return short_name;
}