wildmatch: adjust "**" behavior
[git/git.git] / wildmatch.c
index eef7b13..85bc0df 100644 (file)
@@ -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)
@@ -71,6 +66,8 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
                        return ABORT_ALL;
                if (force_lower_case && ISUPPER(t_ch))
                        t_ch = tolower(t_ch);
+               if (force_lower_case && ISUPPER(p_ch))
+                       p_ch = tolower(p_ch);
                switch (p_ch) {
                case '\\':
                        /* Literal match with following character.  Note that the test
@@ -88,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') {