Commit cfbc880d by Russell Belfer

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
parent 1dbcc9fc
......@@ -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
......
......@@ -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
......@@ -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 */
......
......@@ -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)
......
......@@ -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;
}
......@@ -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
......@@ -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;
}
......@@ -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;
}
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment