summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2016-04-18 16:05:12 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2016-04-19 19:39:06 +0200
commitd45928cc0d969f255337e11edd59b4da6dc4926d (patch)
treec2c66e18fbfef1fd323906138516e96f99ba5a73 /src
parent1c3018eb12c03010fe0db740bc9e67af4992e594 (diff)
downloadlibgit2-d45928cc0d969f255337e11edd59b4da6dc4926d.tar.gz
ignore: move star-star matching closer to it usecmn/ignore-starstar
Instead of threading the state down to the larger loop, let's have the loop where we detect the double star so each of them are easier to read.
Diffstat (limited to 'src')
-rw-r--r--src/fnmatch.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/fnmatch.c b/src/fnmatch.c
index ba1964bf8..33c8a2512 100644
--- a/src/fnmatch.c
+++ b/src/fnmatch.c
@@ -69,8 +69,7 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
if (recurs-- == 0)
return FNM_NORES;
- for (stringstart = string;;) {
- bool match_slash = false;
+ for (stringstart = string;;)
switch (c = *pattern++) {
case EOS:
if ((flags & FNM_LEADING_DIR) && *string == '/')
@@ -103,8 +102,15 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
return (FNM_NOMATCH);
c = *++pattern;
- flags &= ~FNM_PATHNAME;
- match_slash = true;
+ do {
+ int e = p_fnmatchx(pattern, string, recurs_flags, recurs);
+ if (e != FNM_NOMATCH)
+ return e;
+ string = strchr(string, '/');
+ } while (string++);
+
+ /* If we get here, we didn't find a match */
+ return FNM_NOMATCH;
}
if (*string == '.' && (flags & FNM_PERIOD) &&
@@ -135,17 +141,7 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
return e;
if (test == '/' && (flags & FNM_PATHNAME))
break;
-
- /* searching for star-star, so we jump over entire dirs */
- if (match_slash) {
- const char *slash;
- if (!(slash = strchr(string, '/')))
- break;
-
- string = slash + 1;
- } else {
- ++string;
- }
+ ++string;
}
return (FNM_NOMATCH);
case '[':
@@ -187,7 +183,6 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
++string;
break;
}
- }
/* NOTREACHED */
}