]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/tag-list-multiple-patterns' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 16 Aug 2011 19:41:14 +0000 (12:41 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Aug 2011 19:41:14 +0000 (12:41 -0700)
* jk/tag-list-multiple-patterns:
  tag: accept multiple patterns for --list

1  2 
builtin/tag.c

diff --combined builtin/tag.c
index ec926fc8ee4512abddc67309421b4394706329f5,55c472102876463a1021aa8c919a91b31f3081e9..cef27263bc79e519398ae5eb0a49d78f3b389090
@@@ -16,7 -16,7 +16,7 @@@
  static const char * const git_tag_usage[] = {
        "git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]",
        "git tag -d <tagname>...",
-       "git tag -l [-n[<num>]] [<pattern>]",
+       "git tag -l [-n[<num>]] [<pattern>...]",
        "git tag -v <tagname>...",
        NULL
  };
  static char signingkey[1000];
  
  struct tag_filter {
-       const char *pattern;
+       const char **patterns;
        int lines;
        struct commit_list *with_commit;
  };
  
+ static int match_pattern(const char **patterns, const char *ref)
+ {
+       /* no pattern means match everything */
+       if (!*patterns)
+               return 1;
+       for (; *patterns; patterns++)
+               if (!fnmatch(*patterns, ref, 0))
+                       return 1;
+       return 0;
+ }
  static int show_reference(const char *refname, const unsigned char *sha1,
                          int flag, void *cb_data)
  {
        struct tag_filter *filter = cb_data;
  
-       if (!fnmatch(filter->pattern, refname, 0)) {
+       if (match_pattern(filter->patterns, refname)) {
                int i;
                unsigned long size;
                enum object_type type;
        return 0;
  }
  
- static int list_tags(const char *pattern, int lines,
+ static int list_tags(const char **patterns, int lines,
                        struct commit_list *with_commit)
  {
        struct tag_filter filter;
  
-       if (pattern == NULL)
-               pattern = "*";
-       filter.pattern = pattern;
+       filter.patterns = patterns;
        filter.lines = lines;
        filter.with_commit = with_commit;
  
@@@ -352,22 -360,11 +360,22 @@@ static int parse_msg_arg(const struct o
        return 0;
  }
  
 +static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
 +{
 +      if (name[0] == '-')
 +              return CHECK_REF_FORMAT_ERROR;
 +
 +      strbuf_reset(sb);
 +      strbuf_addf(sb, "refs/tags/%s", name);
 +
 +      return check_ref_format(sb->buf);
 +}
 +
  int cmd_tag(int argc, const char **argv, const char *prefix)
  {
        struct strbuf buf = STRBUF_INIT;
 +      struct strbuf ref = STRBUF_INIT;
        unsigned char object[20], prev[20];
 -      char ref[PATH_MAX];
        const char *object_ref, *tag;
        struct ref_lock *lock;
  
        if (list + delete + verify > 1)
                usage_with_options(git_tag_usage, options);
        if (list)
-               return list_tags(argv[0], lines == -1 ? 0 : lines,
+               return list_tags(argv, lines == -1 ? 0 : lines,
                                 with_commit);
        if (lines != -1)
                die(_("-n option is only allowed with -l."));
        if (get_sha1(object_ref, object))
                die(_("Failed to resolve '%s' as a valid ref."), object_ref);
  
 -      if (snprintf(ref, sizeof(ref), "refs/tags/%s", tag) > sizeof(ref) - 1)
 -              die(_("tag name too long: %.*s..."), 50, tag);
 -      if (check_ref_format(ref))
 +      if (strbuf_check_tag_ref(&ref, tag))
                die(_("'%s' is not a valid tag name."), tag);
  
 -      if (!resolve_ref(ref, prev, 1, NULL))
 +      if (!resolve_ref(ref.buf, prev, 1, NULL))
                hashclr(prev);
        else if (!force)
                die(_("tag '%s' already exists"), tag);
                create_tag(object, tag, &buf, msg.given || msgfile,
                           sign, prev, object);
  
 -      lock = lock_any_ref_for_update(ref, prev, 0);
 +      lock = lock_any_ref_for_update(ref.buf, prev, 0);
        if (!lock)
 -              die(_("%s: cannot lock the ref"), ref);
 +              die(_("%s: cannot lock the ref"), ref.buf);
        if (write_ref_sha1(lock, object, NULL) < 0)
 -              die(_("%s: cannot update the ref"), ref);
 +              die(_("%s: cannot update the ref"), ref.buf);
        if (force && hashcmp(prev, object))
                printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV));
  
        strbuf_release(&buf);
 +      strbuf_release(&ref);
        return 0;
  }