提交 46e1d6eb 编写于 作者: J Junio C Hamano

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: NJunio C Hamano <gitster@pobox.com>
上级 8d44277d
......@@ -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)
{
int might_be_tag = !prefixcmp(path, "refs/tags/");
int is_tag = !prefixcmp(path, "refs/tags/");
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;
/* 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)) {
is_tag = !!hashcmp(sha1, peeled);
is_annotated = !!hashcmp(sha1, peeled);
} else {
hashcpy(peeled, sha1);
is_tag = 0;
is_annotated = 0;
}
/* If --all, then any refs are used.
* If --tags, then any tags are used.
* Otherwise only annotated tags are used.
/*
* By default, we only use annotated tags, but with --tags
* 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_tag)
prio = 2;
else
prio = 1;
if (pattern && fnmatch(pattern, path + 10, 0))
prio = 0;
}
if (is_annotated)
prio = 2;
else if (is_tag)
prio = 1;
else
prio = 0;
if (!all) {
if (!prio)
return 0;
}
add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1);
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册