From: Junio C Hamano Date: Tue, 19 Jul 2011 16:45:15 +0000 (-0700) Subject: Merge branch 'jk/tag-list-multiple-patterns' X-Git-Tag: v1.7.7-rc0~92 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/20a80d04a4835dfec2823570719f17b6892e4841?ds=inline;hp=-c Merge branch 'jk/tag-list-multiple-patterns' * jk/tag-list-multiple-patterns: tag: accept multiple patterns for --list --- 20a80d04a4835dfec2823570719f17b6892e4841 diff --combined builtin/tag.c index ec926fc8ee,55c4721028..cef27263bc --- a/builtin/tag.c +++ b/builtin/tag.c @@@ -16,7 -16,7 +16,7 @@@ static const char * const git_tag_usage[] = { "git tag [-a|-s|-u ] [-f] [-m |-F ] []", "git tag -d ...", - "git tag -l [-n[]] []", + "git tag -l [-n[]] [...]", "git tag -v ...", NULL }; @@@ -24,17 -24,28 +24,28 @@@ 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; @@@ -88,15 -99,12 +99,12 @@@ 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; @@@ -425,7 -422,7 +433,7 @@@ 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.")); @@@ -463,10 -460,12 +471,10 @@@ 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); @@@ -475,15 -474,14 +483,15 @@@ 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; }