describe: --match=<pattern> must limit the refs even when used with --all
The logic to limit the refs used for describing with a matching pattern with --match=<pattern> parameter was implemented incorrectly when --all is in effect. It just demoted a ref that did not match the pattern to lower priority---if there aren't other refs with higher priority that describe the given commit, such an unmatching ref was still used. When --match is used, reject refs that do not match the given criteria, so that with or without --all, the output will only use refs that match the pattern. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
8d44277d91
commit
46e1d6eb4d
@ -137,40 +137,39 @@ static void add_to_known_names(const char *path,
|
|||||||
|
|
||||||
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
|
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
|
||||||
{
|
{
|
||||||
int might_be_tag = !prefixcmp(path, "refs/tags/");
|
int is_tag = !prefixcmp(path, "refs/tags/");
|
||||||
unsigned char peeled[20];
|
unsigned char peeled[20];
|
||||||
int is_tag, prio;
|
int is_annotated, prio;
|
||||||
|
|
||||||
if (!all && !might_be_tag)
|
/* Reject anything outside refs/tags/ unless --all */
|
||||||
|
if (!all && !is_tag)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/* Accept only tags that match the pattern, if given */
|
||||||
|
if (pattern && (!is_tag || fnmatch(pattern, path + 10, 0)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Is it annotated? */
|
||||||
if (!peel_ref(path, peeled)) {
|
if (!peel_ref(path, peeled)) {
|
||||||
is_tag = !!hashcmp(sha1, peeled);
|
is_annotated = !!hashcmp(sha1, peeled);
|
||||||
} else {
|
} else {
|
||||||
hashcpy(peeled, sha1);
|
hashcpy(peeled, sha1);
|
||||||
is_tag = 0;
|
is_annotated = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If --all, then any refs are used.
|
/*
|
||||||
* If --tags, then any tags are used.
|
* By default, we only use annotated tags, but with --tags
|
||||||
* Otherwise only annotated tags are used.
|
* we fall back to lightweight ones (even without --tags,
|
||||||
|
* we still remember lightweight ones, only to give hints
|
||||||
|
* in an error message). --all allows any refs to be used.
|
||||||
*/
|
*/
|
||||||
if (might_be_tag) {
|
if (is_annotated)
|
||||||
if (is_tag)
|
|
||||||
prio = 2;
|
prio = 2;
|
||||||
else
|
else if (is_tag)
|
||||||
prio = 1;
|
prio = 1;
|
||||||
|
|
||||||
if (pattern && fnmatch(pattern, path + 10, 0))
|
|
||||||
prio = 0;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
prio = 0;
|
prio = 0;
|
||||||
|
|
||||||
if (!all) {
|
|
||||||
if (!prio)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1);
|
add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user