]> git.ipfire.org Git - thirdparty/git.git/commitdiff
wildmatch: fix "**" special case
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Tue, 1 Jan 2013 02:44:02 +0000 (09:44 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Jan 2013 23:31:18 +0000 (15:31 -0800)
"**" is adjusted to only be effective when surrounded by slashes, in
40bbee0 (wildmatch: adjust "**" behavior - 2012-10-15). Except that
the commit did it wrong:

1. when it checks for "the preceding slash unless ** is at the
   beginning", it compares to wrong pointer. It should have compared
   to the beginning of the pattern, not the text.

2. prev_p points to the character before "**", not the first "*". The
   correct comparison must be "prev_p < pattern" or
   "prev_p + 1 == pattern", not "prev_p == pattern".

3. The pattern must be surrounded by slashes unless it's at the
   beginning or the end of the pattern. We do two checks: one for the
   preceding slash and one the trailing slash. Both checks must be
   met. The use of "||" is wrong.

This patch fixes all above.

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 d5bafefbe287fa70b3f18bef497292dba58e5637..af54c831111e6b74f892fefde220921eb5e83fa8 100755 (executable)
@@ -83,7 +83,7 @@ match 0 0 'deep/foo/bar/baz/' '**/bar/*'
 match 1 0 'deep/foo/bar/baz/' '**/bar/**'
 match 0 0 'deep/foo/bar' '**/bar/*'
 match 1 0 'deep/foo/bar/' '**/bar/**'
-match 1 0 'foo/bar/baz' '**/bar**'
+match 0 0 'foo/bar/baz' '**/bar**'
 match 1 0 'foo/bar/baz/x' '*/bar/**'
 match 0 0 'deep/foo/bar/baz/x' '*/bar/**'
 match 1 0 'deep/foo/bar/baz/x' '**/bar/*/*'
index 3972e26e83a5131f746399deaa32835c7c9915cb..5f976e91d84f099bab8f8b89f261ccd39d132ceb 100644 (file)
@@ -58,6 +58,7 @@ typedef unsigned char uchar;
 static int dowild(const uchar *p, const uchar *text, int force_lower_case)
 {
        uchar p_ch;
+       const uchar *pattern = p;
 
        for ( ; (p_ch = *p) != '\0'; text++, p++) {
                int matched, special;
@@ -87,7 +88,7 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
                        if (*++p == '*') {
                                const uchar *prev_p = p - 2;
                                while (*++p == '*') {}
-                               if ((prev_p == text || *prev_p == '/') ||
+                               if ((prev_p < pattern || *prev_p == '/') &&
                                    (*p == '\0' || *p == '/' ||
                                     (p[0] == '\\' && p[1] == '/'))) {
                                        /*