Merge branch 'jc/describe'
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Mar 2013 21:00:23 +0000 (14:00 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Mar 2013 21:00:24 +0000 (14:00 -0700)
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

1  2 
builtin/describe.c
diff --combined builtin/describe.c
index ca084c675ef80deaac7a3f8615c1ea3329a97421,b2b740dadcce062845e8b1437acadd6a26e40e81..6636a68cd919ba227a10cfa39efcd5f4e77a801d
@@@ -137,40 -137,39 +137,39 @@@ static void add_to_known_names(const ch
  
  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;
  }
@@@ -402,8 -401,8 +401,8 @@@ int cmd_describe(int argc, const char *
        struct option options[] = {
                OPT_BOOLEAN(0, "contains",   &contains, N_("find the tag that comes after the commit")),
                OPT_BOOLEAN(0, "debug",      &debug, N_("debug search strategy on stderr")),
 -              OPT_BOOLEAN(0, "all",        &all, N_("use any ref in .git/refs")),
 -              OPT_BOOLEAN(0, "tags",       &tags, N_("use any tag in .git/refs/tags")),
 +              OPT_BOOLEAN(0, "all",        &all, N_("use any ref")),
 +              OPT_BOOLEAN(0, "tags",       &tags, N_("use any tag, even unannotated")),
                OPT_BOOLEAN(0, "long",       &longformat, N_("always use long format")),
                OPT__ABBREV(&abbrev),
                OPT_SET_INT(0, "exact-match", &max_candidates,