summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2012-08-22 13:15:14 -0700
committerVicent Martí <vicent@github.com>2012-08-22 13:15:14 -0700
commitcfda29e38260f19e77f1746c4f6f1c2cab453934 (patch)
treedd2a15ccec2e763931c9913970d88a5811feb36a /src
parent697665c0c13e45a5d24af85c133ffaa0a0e0f8cc (diff)
parent2fb4e9b3c5fb410164a32724e42a10d1841d02cc (diff)
downloadlibgit2-cfda29e38260f19e77f1746c4f6f1c2cab453934.tar.gz
Merge pull request #891 from arrbee/internal-ignore-api
API for managing in-memory ignore rules
Diffstat (limited to 'src')
-rw-r--r--src/attr.c10
-rw-r--r--src/attr.h1
-rw-r--r--src/ignore.c49
-rw-r--r--src/status.c10
4 files changed, 61 insertions, 9 deletions
diff --git a/src/attr.c b/src/attr.c
index de714a697..8a7ff28c5 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -612,6 +612,16 @@ int git_attr_cache__init(git_repository *repo)
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;
+ if (ret == GIT_ENOTFOUND) {
+ git_buf dflt = GIT_BUF_INIT;
+
+ ret = git_futils_find_global_file(&dflt, GIT_IGNORE_CONFIG_DEFAULT);
+ if (!ret)
+ cache->cfg_excl_file = git_buf_detach(&dflt);
+
+ git_buf_free(&dflt);
+ }
+
giterr_clear();
/* allocate hashtable for attribute and ignore file contents */
diff --git a/src/attr.h b/src/attr.h
index a35b1160f..78cfb57c6 100644
--- a/src/attr.h
+++ b/src/attr.h
@@ -12,6 +12,7 @@
#define GIT_ATTR_CONFIG "core.attributesfile"
#define GIT_IGNORE_CONFIG "core.excludesfile"
+#define GIT_IGNORE_CONFIG_DEFAULT ".config/git/ignore"
typedef struct {
int initialized;
diff --git a/src/ignore.c b/src/ignore.c
index 93d979f1a..1ac8afdf3 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -1,3 +1,4 @@
+#include "git2/ignore.h"
#include "ignore.h"
#include "path.h"
@@ -203,3 +204,51 @@ cleanup:
git_attr_path__free(&path);
return 0;
}
+
+int git_ignore_add_rule(
+ git_repository *repo,
+ const char *rules)
+{
+ int error;
+ git_attr_file *ign_internal;
+
+ error = git_attr_cache__internal_file(
+ repo, GIT_IGNORE_INTERNAL, &ign_internal);
+
+ if (!error && ign_internal != NULL)
+ error = parse_ignore_file(repo, rules, ign_internal);
+
+ return error;
+}
+
+int git_ignore_clear_internal_rules(
+ git_repository *repo)
+{
+ int error;
+ git_attr_file *ign_internal;
+
+ error = git_attr_cache__internal_file(
+ repo, GIT_IGNORE_INTERNAL, &ign_internal);
+
+ if (!error && ign_internal != NULL)
+ git_attr_file__clear_rules(ign_internal);
+
+ return error;
+}
+
+int git_ignore_path_is_ignored(
+ int *ignored,
+ git_repository *repo,
+ const char *path)
+{
+ int error;
+ git_ignores ignores;
+
+ if (git_ignore__for_path(repo, path, &ignores) < 0)
+ return -1;
+
+ error = git_ignore__lookup(&ignores, path, ignored);
+ git_ignore__free(&ignores);
+ return error;
+}
+
diff --git a/src/status.c b/src/status.c
index 8e462552e..3d3d15d77 100644
--- a/src/status.c
+++ b/src/status.c
@@ -243,14 +243,6 @@ int git_status_should_ignore(
git_repository *repo,
const char *path)
{
- int error;
- git_ignores ignores;
-
- if (git_ignore__for_path(repo, path, &ignores) < 0)
- return -1;
-
- error = git_ignore__lookup(&ignores, path, ignored);
- git_ignore__free(&ignores);
- return error;
+ return git_ignore_path_is_ignored(ignored, repo, path);
}