wildmatch: fix "**" special case

"**" 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>

Nguyễn Thái Ngọc Duy committed Jan 1, 2013 at 09:44 UTC 3a078dec3327fb68faa7c800040f89db3e38e6e5
2 files changed +3 -2
t/t3070-wildmatch.sh
+1 -1
@@ -83,7 +83,7 @@ match 0 0 'deep/foo/bar/baz/' '**/bar/*'
83 match 1 0 'deep/foo/bar/baz/' '**/bar/**'
84 match 0 0 'deep/foo/bar' '**/bar/*'
85 match 1 0 'deep/foo/bar/' '**/bar/**'
86 -match 1 0 'foo/bar/baz' '**/bar**'
86 +match 0 0 'foo/bar/baz' '**/bar**'
87 match 1 0 'foo/bar/baz/x' '*/bar/**'
88 match 0 0 'deep/foo/bar/baz/x' '*/bar/**'
89 match 1 0 'deep/foo/bar/baz/x' '**/bar/*/*'
wildmatch.c
+2 -1
@@ -58,6 +58,7 @@ typedef unsigned char uchar;
58 static int dowild(const uchar *p, const uchar *text, int force_lower_case)
59 {
60 uchar p_ch;
61 + const uchar *pattern = p;
62
63 for ( ; (p_ch = *p) != '\0'; text++, p++) {
64 int matched, special;
@@ -87,7 +88,7 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
88 if (*++p == '*') {
89 const uchar *prev_p = p - 2;
90 while (*++p == '*') {}
90 - if ((prev_p == text || *prev_p == '/') ||
91 + if ((prev_p < pattern || *prev_p == '/') &&
92 (*p == '\0' || *p == '/' ||
93 (p[0] == '\\' && p[1] == '/'))) {
94 /*