From: Carlos Rica Date: Sat, 1 Sep 2007 05:10:09 +0000 (+0200) Subject: git-tag: Fix -l option to use better shell style globs. X-Git-Tag: v1.5.3~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=18e32b5b7af4175f852469159d004a2a8de64658;p=git.git git-tag: Fix -l option to use better shell style globs. This patch removes certain behaviour of "git tag -l foo", currently listing every tag name having "foo" as a substring. The same thing now could be achieved doing "git tag -l '*foo*'". This feature was added recently when git-tag.sh got the -n option for showing tag annotations, because that commit also replaced the old "grep pattern" behaviour with a more preferable "shell pattern" behaviour (although slightly modified as you can see). Thus, the following builtin-tag.c implemented it in order to ensure that tests were passing unchanged with both programs. Since common "shell patterns" match names with a given substring _only_ when * is inserted before and after (as in "*substring*"), and the "plain" behaviour cannot be achieved easily with the current implementation, this is mostly the right thing to do, in order to make it more flexible and consistent. Tests for "git tag" were also changed to reflect this. Signed-off-by: Carlos Rica Signed-off-by: Junio C Hamano --- diff --git a/builtin-tag.c b/builtin-tag.c index d6d38ad12..348919cff 100644 --- a/builtin-tag.c +++ b/builtin-tag.c @@ -123,22 +123,15 @@ static int show_reference(const char *refname, const unsigned char *sha1, static int list_tags(const char *pattern, int lines) { struct tag_filter filter; - char *newpattern; if (pattern == NULL) - pattern = ""; + pattern = "*"; - /* prepend/append * to the shell pattern: */ - newpattern = xmalloc(strlen(pattern) + 3); - sprintf(newpattern, "*%s*", pattern); - - filter.pattern = newpattern; + filter.pattern = pattern; filter.lines = lines; for_each_tag_ref(show_reference, (void *) &filter); - free(newpattern); - return 0; } diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index c4fa4461f..606d4f2a2 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -185,18 +185,17 @@ cba EOF test_expect_success \ 'listing tags with substring as pattern must print those matching' ' - git-tag -l a > actual && + git-tag -l "*a*" > actual && git diff expect actual ' cat >expect < actual && + 'listing tags with a suffix as pattern must print those matching' ' + git-tag -l "*.1" > actual && git diff expect actual ' @@ -205,37 +204,36 @@ t210 t211 EOF test_expect_success \ - 'listing tags with substring as pattern must print those matching' ' - git-tag -l t21 > actual && + 'listing tags with a prefix as pattern must print those matching' ' + git-tag -l "t21*" > actual && git diff expect actual ' cat >expect < actual && git diff expect actual ' cat >expect < actual && git diff expect actual ' cat >expect < actual && + git-tag -l "v1.?.?" > actual && git diff expect actual '