Commit 2b6b85f1 by Russell Belfer

Add support for ** matches in ignores

This is an experimental addition to add ** support to fnmatch
pattern matching in libgit2.  It needs more testing.
parent 923c8400
...@@ -30,6 +30,7 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs) ...@@ -30,6 +30,7 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
const char *stringstart; const char *stringstart;
char *newp; char *newp;
char c, test; char c, test;
int recurs_flags = flags & ~FNM_PERIOD;
if (recurs-- == 0) if (recurs-- == 0)
return FNM_NORES; return FNM_NORES;
...@@ -53,9 +54,13 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs) ...@@ -53,9 +54,13 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
break; break;
case '*': case '*':
c = *pattern; c = *pattern;
/* Collapse multiple stars. */
while (c == '*') /* Apply '**' to overwrite PATHNAME match */
if (c == '*') {
flags &= ~FNM_PATHNAME;
while (c == '*')
c = *++pattern; c = *++pattern;
}
if (*string == '.' && (flags & FNM_PERIOD) && if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart || (string == stringstart ||
...@@ -80,7 +85,7 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs) ...@@ -80,7 +85,7 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
while ((test = *string) != EOS) { while ((test = *string) != EOS) {
int e; int e;
e = p_fnmatchx(pattern, string, flags & ~FNM_PERIOD, recurs); e = p_fnmatchx(pattern, string, recurs_flags, recurs);
if (e != FNM_NOMATCH) if (e != FNM_NOMATCH)
return e; return e;
if (test == '/' && (flags & FNM_PATHNAME)) if (test == '/' && (flags & FNM_PATHNAME))
......
...@@ -54,6 +54,19 @@ void test_attr_ignore__ignore_root(void) ...@@ -54,6 +54,19 @@ void test_attr_ignore__ignore_root(void)
assert_is_ignored(true, "NewFolder/NewFolder/File.txt"); assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
} }
void test_attr_ignore__full_paths(void)
{
cl_git_rewritefile("attr/.gitignore", "Folder/*/Contained");
assert_is_ignored(true, "Folder/Middle/Contained");
assert_is_ignored(false, "Folder/Middle/More/More/Contained");
cl_git_rewritefile("attr/.gitignore", "Folder/**/Contained");
assert_is_ignored(true, "Folder/Middle/Contained");
assert_is_ignored(true, "Folder/Middle/More/More/Contained");
}
void test_attr_ignore__skip_gitignore_directory(void) void test_attr_ignore__skip_gitignore_directory(void)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment