]> git.ipfire.org Git - thirdparty/git.git/commitdiff
wildmatch: make /**/ match zero or more directories
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 15 Oct 2012 06:26:01 +0000 (13:26 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Oct 2012 21:58:18 +0000 (14:58 -0700)
"foo/**/bar" matches "foo/x/bar", "foo/x/y/bar"... but not
"foo/bar". We make a special case, when foo/**/ is detected (and
"foo/" part is already matched), try matching "bar" with the rest of
the string.

"Match one or more directories" semantics can be easily achieved using
"foo/*/**/bar".

This also makes "**/foo" match "foo" in addition to "x/foo",
"x/y/foo"..

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3070-wildmatch.sh
wildmatch.c

index 15848d59350c41ced7bafa851f5bd2f888325906..e6ad6f47036d7a3664e6de7db2b6c879fc3601ac 100755 (executable)
@@ -63,11 +63,17 @@ match 1 1 ']' ']'
 match 0 0 'foo/baz/bar' 'foo*bar'
 match 0 0 'foo/baz/bar' 'foo**bar'
 match 0 1 'foobazbar' 'foo**bar'
+match 1 1 'foo/baz/bar' 'foo/**/bar'
+match 1 0 'foo/baz/bar' 'foo/**/**/bar'
+match 1 0 'foo/b/a/z/bar' 'foo/**/bar'
+match 1 0 'foo/b/a/z/bar' 'foo/**/**/bar'
+match 1 0 'foo/bar' 'foo/**/bar'
+match 1 0 'foo/bar' 'foo/**/**/bar'
 match 0 0 'foo/bar' 'foo?bar'
 match 0 0 'foo/bar' 'foo[/]bar'
 match 0 0 'foo/bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
 match 1 1 'foo-bar' 'f[^eiu][^eiu][^eiu][^eiu][^eiu]r'
-match 0 0 'foo' '**/foo'
+match 1 0 'foo' '**/foo'
 match 1 x '/foo' '**/foo'
 match 1 0 'bar/baz/foo' '**/foo'
 match 0 0 'bar/baz/foo' '*/foo'
index 85bc0df8f814f18f9b10f9eccea0620ae8d9b9bc..3972e26e83a5131f746399deaa32835c7c9915cb 100644 (file)
@@ -90,6 +90,18 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
                                if ((prev_p == text || *prev_p == '/') ||
                                    (*p == '\0' || *p == '/' ||
                                     (p[0] == '\\' && p[1] == '/'))) {
+                                       /*
+                                        * Assuming we already match 'foo/' and are at
+                                        * <star star slash>, just assume it matches
+                                        * nothing and go ahead match the rest of the
+                                        * pattern with the remaining string. This
+                                        * helps make foo/<*><*>/bar (<> because
+                                        * otherwise it breaks C comment syntax) match
+                                        * both foo/bar and foo/a/bar.
+                                        */
+                                       if (p[0] == '/' &&
+                                           dowild(p + 1, text, force_lower_case) == MATCH)
+                                               return MATCH;
                                        special = TRUE;
                                } else
                                        return ABORT_MALFORMED;