summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f800b65)
raw | patch | inline | side by side (parent: f800b65)
author | Bert Wesarg <bert.wesarg@googlemail.com> | |
Mon, 13 Apr 2009 10:25:46 +0000 (12:25 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 13 Apr 2009 16:36:44 +0000 (09:36 -0700) |
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>
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>
builtin-branch.c | patch | blob | history | |
builtin-for-each-ref.c | patch | blob | history | |
refs.c | patch | blob | history | |
refs.h | patch | blob | history |
diff --git a/builtin-branch.c b/builtin-branch.c
index 32758216961b9160b32315e9cb0ff9c68f9afdf9..91098ca9b106239916af000cb54a4bf09629e6b6 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
if (branch && branch->merge && branch->merge[0]->dst &&
show_upstream_ref)
strbuf_addf(stat, "[%s] ",
- shorten_unambiguous_ref(branch->merge[0]->dst));
+ shorten_unambiguous_ref(branch->merge[0]->dst, 0));
return;
}
strbuf_addch(stat, '[');
if (show_upstream_ref)
strbuf_addf(stat, "%s: ",
- shorten_unambiguous_ref(branch->merge[0]->dst));
+ shorten_unambiguous_ref(branch->merge[0]->dst, 0));
if (!ours)
strbuf_addf(stat, "behind %d] ", theirs);
else if (!theirs)
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index c8114c8afdb5e5d8a5f0adac2302aa97c384d232..cfff686ac8e151c9624788e27dda9cda268e41e8 100644 (file)
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
if (formatp) {
formatp++;
if (!strcmp(formatp, "short"))
- refname = shorten_unambiguous_ref(refname);
+ refname = shorten_unambiguous_ref(refname, 0);
else
die("unknown %.*s format %s",
(int)(formatp - name), name, formatp);
index 82afb8768473f605bdbce17698b219484890f4f9..e65a3b4c4ef57863a1055108d2598777cabc2c8d 100644 (file)
--- a/refs.c
+++ b/refs.c
return;
}
-char *shorten_unambiguous_ref(const char *ref)
+char *shorten_unambiguous_ref(const char *ref, int strict)
{
int i;
static char **scanf_fmts;
/* 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))
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
* 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;
}
index 50abbbb2aafb5c6a514d3704001f60473b8b1bfa..29d17a48e4a2923bc72337deb1ef64cf7b467381 100644 (file)
--- a/refs.h
+++ b/refs.h
extern int check_ref_format(const char *target);
extern const char *prettify_ref(const struct ref *ref);
-extern char *shorten_unambiguous_ref(const char *ref);
+extern char *shorten_unambiguous_ref(const char *ref, int strict);
/** rename ref, return 0 on success **/
extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);