summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-01-16 15:16:44 -0800
committerRussell Belfer <arrbee@arrbee.com>2012-01-16 15:16:44 -0800
commitcfbc880d8a407bcd2074dda4221d337daf72195c (patch)
treeeb1cd2d1be66c2b5604fbe3699b38aae984851b3
parent1dbcc9fc4e6f5264d5bb46f6d7f744eb4a4063e4 (diff)
downloadlibgit2-cfbc880d8a407bcd2074dda4221d337daf72195c.tar.gz
Patch cleanup for merge
After reviewing the gitignore support with Vicent, we came up with a list of minor cleanups to prepare for merge, including: * checking git_repository_config error returns * renaming git_ignore_is_ignored and moving to status.h * fixing next_line skipping to include \r skips * commenting on where ignores are and are not included
-rw-r--r--include/git2/index.h4
-rw-r--r--include/git2/status.h16
-rw-r--r--src/attr.c7
-rw-r--r--src/attr_file.h5
-rw-r--r--src/ignore.c17
-rw-r--r--src/ignore.h2
-rw-r--r--src/status.c15
-rw-r--r--src/util.h2
-rw-r--r--tests-clay/status/worktree.c6
9 files changed, 46 insertions, 28 deletions
diff --git a/include/git2/index.h b/include/git2/index.h
index 627d6c4fd..5018c896b 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -169,6 +169,10 @@ GIT_EXTERN(void) git_index_uniq(git_index *index);
*
* This method will fail in bare index instances.
*
+ * This forces the file to be added to the index, not looking
+ * at gitignore rules. Those rules can be evaluated through
+ * the git_status APIs (in status.h) before calling this.
+ *
* @param index an existing index object
* @param path filename to add
* @param stage stage for the entry
diff --git a/include/git2/status.h b/include/git2/status.h
index 0f2b63de4..c0f38c508 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -58,6 +58,22 @@ GIT_EXTERN(int) git_status_foreach(git_repository *repo, int (*callback)(const c
*/
GIT_EXTERN(int) git_status_file(unsigned int *status_flags, git_repository *repo, const char *path);
+/**
+ * Test if the ignore rules apply to a given file.
+ *
+ * This function simply checks the ignore rules to see if they would apply
+ * to the given file. Unlike git_status_file(), this indicates if the file
+ * would be ignored regardless of whether the file is already in the index
+ * or in the repository.
+ *
+ * @param repo a repository object
+ * @param path the file to check ignores for, rooted at the repo's workdir
+ * @param ignored boolean returning 0 if the file is not ignored, 1 if it is
+ * @return GIT_SUCCESS if the ignore rules could be processed for the file
+ * (regardless of whether it exists or not), or an error < 0 if they could not.
+ */
+GIT_EXTERN(int) git_status_should_ignore(git_repository *repo, const char *path, int *ignored);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/src/attr.c b/src/attr.c
index cbc2a5bf5..dc42379ff 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -3,11 +3,6 @@
#include "config.h"
#include <ctype.h>
-#define GIT_ATTR_FILE_INREPO "info/attributes"
-#define GIT_ATTR_FILE ".gitattributes"
-#define GIT_ATTR_FILE_SYSTEM "gitattributes"
-#define GIT_ATTR_CONFIG "core.attributesfile"
-
static int collect_attr_files(
git_repository *repo, const char *path, git_vector *files);
@@ -304,7 +299,7 @@ static int collect_attr_files(
if (error < GIT_SUCCESS)
goto cleanup;
- if (git_repository_config(&cfg, repo) == GIT_SUCCESS) {
+ if ((error = git_repository_config(&cfg, repo)) == GIT_SUCCESS) {
const char *core_attribs = NULL;
git_config_get_string(cfg, GIT_ATTR_CONFIG, &core_attribs);
git_clearerror(); /* don't care if attributesfile is not set */
diff --git a/src/attr_file.h b/src/attr_file.h
index 86836b56f..7190c4c7b 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -11,6 +11,11 @@
#include "vector.h"
#include "hashtable.h"
+#define GIT_ATTR_FILE ".gitattributes"
+#define GIT_ATTR_FILE_INREPO "info/attributes"
+#define GIT_ATTR_FILE_SYSTEM "gitattributes"
+#define GIT_ATTR_CONFIG "core.attributesfile"
+
#define GIT_ATTR_FNMATCH_NEGATIVE (1U << 0)
#define GIT_ATTR_FNMATCH_DIRECTORY (1U << 1)
#define GIT_ATTR_FNMATCH_FULLPATH (1U << 2)
diff --git a/src/ignore.c b/src/ignore.c
index cdc3edab6..1040574d7 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -106,7 +106,7 @@ int git_ignore__for_path(git_repository *repo, const char *path, git_vector *sta
goto cleanup;
/* load core.excludesfile */
- if (git_repository_config(&cfg, repo) == GIT_SUCCESS) {
+ if ((error = git_repository_config(&cfg, repo)) == GIT_SUCCESS) {
const char *core_ignore;
error = git_config_get_string(cfg, GIT_IGNORE_CONFIG, &core_ignore);
if (error == GIT_SUCCESS && core_ignore != NULL)
@@ -157,18 +157,3 @@ found:
return error;
}
-
-
-int git_ignore_is_ignored(git_repository *repo, const char *path, int *ignored)
-{
- int error;
- git_vector ignores = GIT_VECTOR_INIT;
-
- if ((error = git_ignore__for_path(repo, path, &ignores)) == GIT_SUCCESS)
- error = git_ignore__lookup(&ignores, path, ignored);
-
- git_ignore__free(&ignores);
-
- return error;
-}
-
diff --git a/src/ignore.h b/src/ignore.h
index a6e6a1a34..2954445b5 100644
--- a/src/ignore.h
+++ b/src/ignore.h
@@ -14,6 +14,4 @@ extern int git_ignore__for_path(git_repository *repo, const char *path, git_vect
extern void git_ignore__free(git_vector *stack);
extern int git_ignore__lookup(git_vector *stack, const char *path, int *ignored);
-extern int git_ignore_is_ignored(git_repository *repo, const char *path, int *ignored);
-
#endif
diff --git a/src/status.c b/src/status.c
index 72ee7b049..3ead15a87 100644
--- a/src/status.c
+++ b/src/status.c
@@ -761,3 +761,18 @@ static int alphasorted_futils_direach(
git_vector_free(&entry_names);
return error;
}
+
+
+int git_status_should_ignore(git_repository *repo, const char *path, int *ignored)
+{
+ int error;
+ git_vector ignores = GIT_VECTOR_INIT;
+
+ if ((error = git_ignore__for_path(repo, path, &ignores)) == GIT_SUCCESS)
+ error = git_ignore__lookup(&ignores, path, ignored);
+
+ git_ignore__free(&ignores);
+
+ return error;
+}
+
diff --git a/src/util.h b/src/util.h
index bd76a263e..6c929cf0a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -105,7 +105,7 @@ extern void git__strtolower(char *str);
GIT_INLINE(const char *) git__next_line(const char *s)
{
while (*s && *s != '\n') s++;
- while (*s == '\n') s++;
+ while (*s == '\n' || *s == '\r') s++;
return s;
}
diff --git a/tests-clay/status/worktree.c b/tests-clay/status/worktree.c
index af6f005a7..2183649f2 100644
--- a/tests-clay/status/worktree.c
+++ b/tests-clay/status/worktree.c
@@ -142,13 +142,13 @@ void test_status_worktree__ignores(void)
int i, ignored;
for (i = 0; i < (int)entry_count0; i++) {
- cl_git_pass(git_ignore_is_ignored(_repository, entry_paths0[i], &ignored));
+ cl_git_pass(git_status_should_ignore(_repository, entry_paths0[i], &ignored));
cl_assert(ignored == (entry_statuses0[i] == GIT_STATUS_IGNORED));
}
- cl_git_pass(git_ignore_is_ignored(_repository, "nonexistent_file", &ignored));
+ cl_git_pass(git_status_should_ignore(_repository, "nonexistent_file", &ignored));
cl_assert(!ignored);
- cl_git_pass(git_ignore_is_ignored(_repository, "ignored_nonexistent_file", &ignored));
+ cl_git_pass(git_status_should_ignore(_repository, "ignored_nonexistent_file", &ignored));
cl_assert(ignored);
}