summaryrefslogtreecommitdiff
path: root/wildmatch.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2012-10-15 13:26:00 +0700
committerJunio C Hamano <gitster@pobox.com>2012-10-15 14:58:18 -0700
commit40bbee0ab07d0ee4f21b11d597c878245c1b05a6 (patch)
treea966918d4df85bb7a398d4b37286b4ba731b7e98 /wildmatch.c
parent164bf83af6466e03b306b9d63dcf7d36dda2bdae (diff)
downloadgit-40bbee0ab07d0ee4f21b11d597c878245c1b05a6.tar.gz
wildmatch: adjust "**" behavior
Standard wildmatch() sees consecutive asterisks as "*" that can also match slashes. But that may be hard to explain to users as "abc/**/def" can match "abcdef", "abcxyzdef", "abc/def", "abc/x/def", "abc/x/y/def"... This patch changes wildmatch so that users can do - "**/def" -> all paths ending with file/directory 'def' - "abc/**" - equivalent to "/abc/" - "abc/**/def" -> "abc/x/def", "abc/x/y/def"... - otherwise consider the pattern malformed if "**" is found Basically the magic of "**" only remains if it's wrapped around by slashes. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wildmatch.c')
-rw-r--r--wildmatch.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/wildmatch.c b/wildmatch.c
index 5469866e8a..85bc0df8f8 100644
--- a/wildmatch.c
+++ b/wildmatch.c
@@ -21,11 +21,6 @@ typedef unsigned char uchar;
#define FALSE 0
#define TRUE 1
-#define NOMATCH 1
-#define MATCH 0
-#define ABORT_ALL -1
-#define ABORT_TO_STARSTAR -2
-
#define CC_EQ(class, len, litmatch) ((len) == sizeof (litmatch)-1 \
&& *(class) == *(litmatch) \
&& strncmp((char*)class, litmatch, len) == 0)
@@ -90,8 +85,14 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
continue;
case '*':
if (*++p == '*') {
+ const uchar *prev_p = p - 2;
while (*++p == '*') {}
- special = TRUE;
+ if ((prev_p == text || *prev_p == '/') ||
+ (*p == '\0' || *p == '/' ||
+ (p[0] == '\\' && p[1] == '/'))) {
+ special = TRUE;
+ } else
+ return ABORT_MALFORMED;
} else
special = FALSE;
if (*p == '\0') {