@matheusbsbs / matheus-bagliano / commits / 18e32b5b7a
Fork 0

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 <jasampler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Carlos Rica committed Sep 1, 2007 at 07:10 UTC 18e32b5b7af4175f852469159d004a2a8de64658
2 files changed +11 -20
builtin-tag.c
+2 -9
@@ -123,22 +123,15 @@ static int show_reference(const char *refname, const unsigned char *sha1,
123 static int list_tags(const char *pattern, int lines)
124 {
125 struct tag_filter filter;
126 - char *newpattern;
126
127 if (pattern == NULL)
129 - pattern = "";
128 + pattern = "*";
129
131 - /* prepend/append * to the shell pattern: */
132 - newpattern = xmalloc(strlen(pattern) + 3);
133 - sprintf(newpattern, "*%s*", pattern);
134 -
135 - filter.pattern = newpattern;
130 + filter.pattern = pattern;
131 filter.lines = lines;
132
133 for_each_tag_ref(show_reference, (void *) &filter);
134
140 - free(newpattern);
141 -
135 return 0;
136 }
137
t/t7004-tag.sh
+9 -11
@@ -185,18 +185,17 @@ cba
185 EOF
186 test_expect_success \
187 'listing tags with substring as pattern must print those matching' '
188 - git-tag -l a > actual &&
188 + git-tag -l "*a*" > actual &&
189 git diff expect actual
190 '
191
192 cat >expect <<EOF
193 v0.2.1
194 v1.0.1
195 -v1.1.3
195 EOF
196 test_expect_success \
198 - 'listing tags with substring as pattern must print those matching' '
199 - git-tag -l .1 > actual &&
197 + 'listing tags with a suffix as pattern must print those matching' '
198 + git-tag -l "*.1" > actual &&
199 git diff expect actual
200 '
201
@@ -205,37 +204,36 @@ t210
204 t211
205 EOF
206 test_expect_success \
208 - 'listing tags with substring as pattern must print those matching' '
209 - git-tag -l t21 > actual &&
207 + 'listing tags with a prefix as pattern must print those matching' '
208 + git-tag -l "t21*" > actual &&
209 git diff expect actual
210 '
211
212 cat >expect <<EOF
213 a1
215 -aa1
214 EOF
215 test_expect_success \
218 - 'listing tags using a name as pattern must print those matching' '
216 + 'listing tags using a name as pattern must print that one matching' '
217 git-tag -l a1 > actual &&
218 git diff expect actual
219 '
220
221 cat >expect <<EOF
222 v1.0
225 -v1.0.1
223 EOF
224 test_expect_success \
228 - 'listing tags using a name as pattern must print those matching' '
225 + 'listing tags using a name as pattern must print that one matching' '
226 git-tag -l v1.0 > actual &&
227 git diff expect actual
228 '
229
230 cat >expect <<EOF
231 +v1.0.1
232 v1.1.3
233 EOF
234 test_expect_success \
235 'listing tags with ? in the pattern should print those matching' '
238 - git-tag -l "1.1?" > actual &&
236 + git-tag -l "v1.?.?" > actual &&
237 git diff expect actual
238 '
239