summaryrefslogtreecommitdiff
path: root/src/ignore.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-08-07 09:17:20 -0700
committerRussell Belfer <rb@github.com>2013-08-09 11:41:41 -0700
commitba8b8c040744edb9bc832a67646e0126636753bb (patch)
treee82808b0e09eb1b344f76b6f1d76883967e487d4 /src/ignore.c
parentd1be9e4ca18caa37c69afb988994a99cd137a3b8 (diff)
downloadlibgit2-ba8b8c040744edb9bc832a67646e0126636753bb.tar.gz
Improve building ignore file lists
The routines to push and pop ignore files while traversing a directory had some issues. In particular, setting up the initial list would sometimes push an ignore file before it ought to be applied if the starting path was a directory containing an ignore file. Also, the pop function was not always matching the right part of the path and would fail to pop ignores from the list in some cases. This adds some tests that exercise a particular problematic case and then fixes the problems that I could find related to this. At some point, I'd like to isolate this ignore rule management code and rewrite it, but that's a larger project and right now, I'll opt to just try to fix the broken behaviors.
Diffstat (limited to 'src/ignore.c')
-rw-r--r--src/ignore.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/ignore.c b/src/ignore.c
index 3c23158c2..ca63f0bd9 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -159,17 +159,26 @@ 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)
+ size_t keylen = strlen(file->key);
+
+ while (keylen && file->key[keylen] != '/')
+ keylen--;
+ keylen -= 1; /* because we will skip "0#" prefix */
+
+ if (ign->dir.size > keylen &&
+ !memcmp(ign->dir.ptr + ign->dir.size - keylen,
+ file->key + 2, keylen))
git_vector_pop(&ign->ign_path);
+
git_buf_rtruncate_at_char(&ign->dir, '/');
}
return 0;
@@ -298,12 +307,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 +333,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++;