mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
wildmatch: support "no FNM_PATHNAME" mode
So far, wildmatch() has always honoured directory boundary and there was no way to turn it off. Make it behave more like fnmatch() by requiring all callers that want the FNM_PATHNAME behaviour to pass that in the equivalent flag WM_PATHNAME. Callers that do not specify WM_PATHNAME will get wildcards like ? and * in their patterns matched against '/', just like not passing FNM_PATHNAME to fnmatch(). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
0c528168da
commit
c41244e702
13
wildmatch.c
13
wildmatch.c
@@ -78,14 +78,17 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
|
||||
continue;
|
||||
case '?':
|
||||
/* Match anything but '/'. */
|
||||
if (t_ch == '/')
|
||||
if ((flags & WM_PATHNAME) && t_ch == '/')
|
||||
return WM_NOMATCH;
|
||||
continue;
|
||||
case '*':
|
||||
if (*++p == '*') {
|
||||
const uchar *prev_p = p - 2;
|
||||
while (*++p == '*') {}
|
||||
if ((prev_p < pattern || *prev_p == '/') &&
|
||||
if (!(flags & WM_PATHNAME))
|
||||
/* without WM_PATHNAME, '*' == '**' */
|
||||
match_slash = 1;
|
||||
else if ((prev_p < pattern || *prev_p == '/') &&
|
||||
(*p == '\0' || *p == '/' ||
|
||||
(p[0] == '\\' && p[1] == '/'))) {
|
||||
/*
|
||||
@@ -104,7 +107,8 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
|
||||
} else
|
||||
return WM_ABORT_MALFORMED;
|
||||
} else
|
||||
match_slash = 0;
|
||||
/* without WM_PATHNAME, '*' == '**' */
|
||||
match_slash = flags & WM_PATHNAME ? 0 : 1;
|
||||
if (*p == '\0') {
|
||||
/* Trailing "**" matches everything. Trailing "*" matches
|
||||
* only if there are no more slash characters. */
|
||||
@@ -215,7 +219,8 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
|
||||
} else if (t_ch == p_ch)
|
||||
matched = 1;
|
||||
} while (prev_ch = p_ch, (p_ch = *++p) != ']');
|
||||
if (matched == negated || t_ch == '/')
|
||||
if (matched == negated ||
|
||||
((flags & WM_PATHNAME) && t_ch == '/'))
|
||||
return WM_NOMATCH;
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user