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>
This commit is contained in:
parent
f800b65bea
commit
6e7b3309d3
@ -311,14 +311,14 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
|
|||||||
if (branch && branch->merge && branch->merge[0]->dst &&
|
if (branch && branch->merge && branch->merge[0]->dst &&
|
||||||
show_upstream_ref)
|
show_upstream_ref)
|
||||||
strbuf_addf(stat, "[%s] ",
|
strbuf_addf(stat, "[%s] ",
|
||||||
shorten_unambiguous_ref(branch->merge[0]->dst));
|
shorten_unambiguous_ref(branch->merge[0]->dst, 0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_addch(stat, '[');
|
strbuf_addch(stat, '[');
|
||||||
if (show_upstream_ref)
|
if (show_upstream_ref)
|
||||||
strbuf_addf(stat, "%s: ",
|
strbuf_addf(stat, "%s: ",
|
||||||
shorten_unambiguous_ref(branch->merge[0]->dst));
|
shorten_unambiguous_ref(branch->merge[0]->dst, 0));
|
||||||
if (!ours)
|
if (!ours)
|
||||||
strbuf_addf(stat, "behind %d] ", theirs);
|
strbuf_addf(stat, "behind %d] ", theirs);
|
||||||
else if (!theirs)
|
else if (!theirs)
|
||||||
|
@ -601,7 +601,7 @@ static void populate_value(struct refinfo *ref)
|
|||||||
if (formatp) {
|
if (formatp) {
|
||||||
formatp++;
|
formatp++;
|
||||||
if (!strcmp(formatp, "short"))
|
if (!strcmp(formatp, "short"))
|
||||||
refname = shorten_unambiguous_ref(refname);
|
refname = shorten_unambiguous_ref(refname, 0);
|
||||||
else
|
else
|
||||||
die("unknown %.*s format %s",
|
die("unknown %.*s format %s",
|
||||||
(int)(formatp - name), name, formatp);
|
(int)(formatp - name), name, formatp);
|
||||||
|
18
refs.c
18
refs.c
@ -1681,7 +1681,7 @@ static void gen_scanf_fmt(char *scanf_fmt, const char *rule)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *shorten_unambiguous_ref(const char *ref)
|
char *shorten_unambiguous_ref(const char *ref, int strict)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
static char **scanf_fmts;
|
static char **scanf_fmts;
|
||||||
@ -1718,6 +1718,7 @@ char *shorten_unambiguous_ref(const char *ref)
|
|||||||
/* skip first rule, it will always match */
|
/* skip first rule, it will always match */
|
||||||
for (i = nr_rules - 1; i > 0 ; --i) {
|
for (i = nr_rules - 1; i > 0 ; --i) {
|
||||||
int j;
|
int j;
|
||||||
|
int rules_to_fail = i;
|
||||||
int short_name_len;
|
int short_name_len;
|
||||||
|
|
||||||
if (1 != sscanf(ref, scanf_fmts[i], short_name))
|
if (1 != sscanf(ref, scanf_fmts[i], short_name))
|
||||||
@ -1725,15 +1726,26 @@ char *shorten_unambiguous_ref(const char *ref)
|
|||||||
|
|
||||||
short_name_len = strlen(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,
|
* check if the short name resolves to a valid ref,
|
||||||
* but use only rules prior to the matched one
|
* 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];
|
const char *rule = ref_rev_parse_rules[j];
|
||||||
unsigned char short_objectname[20];
|
unsigned char short_objectname[20];
|
||||||
char refname[PATH_MAX];
|
char refname[PATH_MAX];
|
||||||
|
|
||||||
|
/* skip matched rule */
|
||||||
|
if (i == j)
|
||||||
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the short name is ambiguous, if it resolves
|
* the short name is ambiguous, if it resolves
|
||||||
* (with this previous rule) to a valid ref
|
* (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
|
* short name is non-ambiguous if all previous rules
|
||||||
* haven't resolved to a valid ref
|
* haven't resolved to a valid ref
|
||||||
*/
|
*/
|
||||||
if (j == i)
|
if (j == rules_to_fail)
|
||||||
return short_name;
|
return short_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
refs.h
2
refs.h
@ -81,7 +81,7 @@ extern int for_each_reflog(each_ref_fn, void *);
|
|||||||
extern int check_ref_format(const char *target);
|
extern int check_ref_format(const char *target);
|
||||||
|
|
||||||
extern const char *prettify_ref(const struct ref *ref);
|
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 **/
|
/** rename ref, return 0 on success **/
|
||||||
extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
|
extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
|
||||||
|
Loading…
Reference in New Issue
Block a user