summaryrefslogtreecommitdiff
path: root/src/ignore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ignore.c')
-rw-r--r--src/ignore.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/ignore.c b/src/ignore.c
index cc90b0c61..27d7c7ec4 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -1,4 +1,5 @@
#include "git2/ignore.h"
+#include "common.h"
#include "ignore.h"
#include "attr.h"
#include "path.h"
@@ -37,7 +38,7 @@ static int parse_ignore_file(
GITERR_CHECK_ALLOC(match);
}
- match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE;
+ match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG;
if (!(error = git_attr_fnmatch__parse(
match, ignores->pool, context, &scan)))
@@ -159,17 +160,36 @@ int git_ignore__push_dir(git_ignores *ign, const char *dir)
{
if (git_buf_joinpath(&ign->dir, ign->dir.ptr, dir) < 0)
return -1;
- else
- return push_ignore_file(
- ign->repo, ign, &ign->ign_path, ign->dir.ptr, GIT_IGNORE_FILE);
+
+ return push_ignore_file(
+ ign->repo, ign, &ign->ign_path, ign->dir.ptr, GIT_IGNORE_FILE);
}
int git_ignore__pop_dir(git_ignores *ign)
{
if (ign->ign_path.length > 0) {
git_attr_file *file = git_vector_last(&ign->ign_path);
- if (git__suffixcmp(ign->dir.ptr, file->key + 2) == 0)
+ const char *start, *end, *scan;
+ size_t keylen;
+
+ /* - ign->dir looks something like "a/b" (or "a/b/c/d")
+ * - file->key looks something like "0#a/b/.gitignore
+ *
+ * We are popping the last directory off ign->dir. We also want to
+ * remove the file from the vector if the directory part of the key
+ * matches the ign->dir path. We need to test if the "a/b" part of
+ * the file key matches the path we are about to pop.
+ */
+
+ for (start = end = scan = &file->key[2]; *scan; ++scan)
+ if (*scan == '/')
+ end = scan; /* point 'end' to last '/' in key */
+ keylen = (end - start) + 1;
+
+ if (ign->dir.size >= keylen &&
+ !memcmp(ign->dir.ptr + ign->dir.size - keylen, start, keylen))
git_vector_pop(&ign->ign_path);
+
git_buf_rtruncate_at_char(&ign->dir, '/');
}
return 0;
@@ -298,12 +318,9 @@ int git_ignore_path_is_ignored(
path.full.size = (tail - path.full.ptr);
path.is_dir = (tail == end) ? full_is_dir : true;
- /* update ignores for new path fragment */
- if (path.basename == path.path)
- error = git_ignore__for_path(repo, path.path, &ignores);
- else
- error = git_ignore__push_dir(&ignores, path.basename);
- if (error < 0)
+ /* initialize ignores the first time through */
+ if (path.basename == path.path &&
+ (error = git_ignore__for_path(repo, path.path, &ignores)) < 0)
break;
/* first process builtins - success means path was found */
@@ -327,6 +344,10 @@ int git_ignore_path_is_ignored(
if (tail == end)
break;
+ /* now add this directory to list of ignores */
+ if ((error = git_ignore__push_dir(&ignores, path.path)) < 0)
+ break;
+
/* reinstate divider in path */
*tail = '/';
while (*tail == '/') tail++;