diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-03-25 14:00:23 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-03-25 14:00:24 -0700 |
commit | 4744b33705b7e4920cf7751ecafaac78927615b7 (patch) | |
tree | 747ade064846d3d91e89e0f09f83fc87f1b24054 /builtin/describe.c | |
parent | a8aa360017e80b9537058caffa53b573df783cae (diff) | |
parent | 46e1d6eb4dcdd2952149fae214aeaa32f29c8df5 (diff) | |
download | git-4744b33705b7e4920cf7751ecafaac78927615b7.tar.gz git-4744b33705b7e4920cf7751ecafaac78927615b7.tar.xz |
Merge branch 'jc/describe'
The "--match=<pattern>" option of "git describe", when used with
"--all" to allow refs that are not annotated tags to be used as a
base of description, did not restrict the output from the command
to those that match the given pattern.
We may want to have a looser matching that does not restrict to tags,
but that can be done as a follow-up topic; this step is purely a bugfix.
* jc/describe:
describe: --match=<pattern> must limit the refs even when used with --all
Diffstat (limited to 'builtin/describe.c')
-rw-r--r-- | builtin/describe.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/builtin/describe.c b/builtin/describe.c index ca084c675..6636a68cd 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -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; } |