summaryrefslogtreecommitdiff
path: root/src/ignore.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-01-16 16:58:27 -0800
committerRussell Belfer <arrbee@arrbee.com>2012-01-16 16:58:27 -0800
commita51cd8e6f6724079a552b75e014f792f3f68e158 (patch)
treefcf526f2a7575e215d95589d1a8e07277981fd18 /src/ignore.c
parent6e03b12f5715cb3f5cb5c8be6512e041cdf44a05 (diff)
downloadlibgit2-a51cd8e6f6724079a552b75e014f792f3f68e158.tar.gz
Fix handling of relative paths for attrs
Per issue #533, the handling of relative paths in attribute and ignore files was not right. Fixed this by pre-joining the relative path of the attribute/ignore file onto the match string when a full path match is required. Unfortunately, fixing this required a bit more code than I would have liked because I had to juggle things around so that the fnmatch parser would have sufficient information to prepend the relative path when it was needed.
Diffstat (limited to 'src/ignore.c')
-rw-r--r--src/ignore.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/ignore.c b/src/ignore.c
index 1040574d7..388a4b280 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -8,22 +8,25 @@
#define GIT_IGNORE_CONFIG "core.excludesfile"
static int load_ignore_file(
- git_repository *GIT_UNUSED(repo), const char *path, git_attr_file **out)
+ git_repository *repo, const char *path, git_attr_file *ignores)
{
int error = GIT_SUCCESS;
git_fbuffer fbuf = GIT_FBUFFER_INIT;
- git_attr_file *ignores = NULL;
git_attr_fnmatch *match = NULL;
const char *scan = NULL;
+ char *context = NULL;
- GIT_UNUSED_ARG(repo);
+ if (ignores->path == NULL)
+ error = git_attr_file__set_path(repo, path, ignores);
- *out = NULL;
-
- if ((error = git_futils_readbuffer(&fbuf, path)) == GIT_SUCCESS)
- error = git_attr_file__new(&ignores);
+ if (git__suffixcmp(ignores->path, GIT_IGNORE_FILE) == 0) {
+ context = git__strndup(ignores->path,
+ strlen(ignores->path) - strlen(GIT_IGNORE_FILE));
+ if (!context) error = GIT_ENOMEM;
+ }
- ignores->path = git__strdup(path);
+ if (error == GIT_SUCCESS)
+ error = git_futils_readbuffer(&fbuf, path);
scan = fbuf.data;
@@ -33,7 +36,7 @@ static int load_ignore_file(
break;
}
- if (!(error = git_attr_fnmatch__parse(match, &scan))) {
+ if (!(error = git_attr_fnmatch__parse(match, context, &scan))) {
match->flags = match->flags | GIT_ATTR_FNMATCH_IGNORE;
scan = git__next_line(scan);
error = git_vector_insert(&ignores->rules, match);
@@ -52,13 +55,10 @@ static int load_ignore_file(
git_futils_freebuffer(&fbuf);
git__free(match);
+ git__free(context);
- if (error != GIT_SUCCESS) {
+ if (error != GIT_SUCCESS)
git__rethrow(error, "Could not open ignore file '%s'", path);
- git_attr_file__free(ignores);
- } else {
- *out = ignores;
- }
return error;
}