summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-03-16 15:56:01 -0700
committerRussell Belfer <arrbee@arrbee.com>2012-03-16 15:56:01 -0700
commit0d0fa7c3681e4ef3d0452666a9bc97d4b08391c9 (patch)
tree5e03e03bf9dc2f6125f4fb450cd3239d882b824f
parent4cfe2ab60b1e26554b2bf753b06f538cb3475bd0 (diff)
downloadlibgit2-0d0fa7c3681e4ef3d0452666a9bc97d4b08391c9.tar.gz
Convert attr, ignore, mwindow, status to new errors
Also cleaned up some previously converted code that still had little things to polish.
-rw-r--r--src/attr.c94
-rw-r--r--src/attr.h4
-rw-r--r--src/attr_file.c2
-rw-r--r--src/blob.c2
-rw-r--r--src/buffer.c40
-rw-r--r--src/buffer.h16
-rw-r--r--src/cache.c5
-rw-r--r--src/diff.c4
-rw-r--r--src/filebuf.c2
-rw-r--r--src/fileops.c10
-rw-r--r--src/fileops.h19
-rw-r--r--src/ignore.c105
-rw-r--r--src/iterator.c102
-rw-r--r--src/mwindow.c31
-rw-r--r--src/odb_loose.c4
-rw-r--r--src/odb_pack.c2
-rw-r--r--src/pack.c2
-rw-r--r--src/path.c2
-rw-r--r--src/path.h4
-rw-r--r--src/refs.c8
-rw-r--r--src/repository.c2
-rw-r--r--src/status.c350
-rw-r--r--src/util.c5
-rw-r--r--tests-clar/attr/repo.c8
-rw-r--r--tests-clar/core/path.c2
-rw-r--r--tests-clar/object/tree/diff.c4
-rw-r--r--tests-clar/status/ignore.c4
-rw-r--r--tests-clar/status/worktree.c4
-rw-r--r--tests/t18-status.c2
29 files changed, 360 insertions, 479 deletions
diff --git a/src/attr.c b/src/attr.c
index a0d6f2954..2c5add34f 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -22,9 +22,9 @@ int git_attr_get(
*value = NULL;
if ((error = git_attr_path__init(
- &path, pathname, git_repository_workdir(repo))) < GIT_SUCCESS ||
- (error = collect_attr_files(repo, pathname, &files)) < GIT_SUCCESS)
- return git__rethrow(error, "Could not get attribute for %s", pathname);
+ &path, pathname, git_repository_workdir(repo))) < 0 ||
+ (error = collect_attr_files(repo, pathname, &files)) < 0)
+ return error;
attr.name = name;
attr.name_hash = git_attr_file__name_hash(name);
@@ -33,8 +33,6 @@ int git_attr_get(
git_attr_file__foreach_matching_rule(file, &path, j, rule) {
int pos = git_vector_bsearch(&rule->assigns, &attr);
- git_clearerror(); /* okay if search failed */
-
if (pos >= 0) {
*value = ((git_attr_assignment *)git_vector_get(
&rule->assigns, pos))->value;
@@ -71,14 +69,12 @@ int git_attr_get_many(
memset((void *)values, 0, sizeof(const char *) * num_attr);
if ((error = git_attr_path__init(
- &path, pathname, git_repository_workdir(repo))) < GIT_SUCCESS ||
- (error = collect_attr_files(repo, pathname, &files)) < GIT_SUCCESS)
- return git__rethrow(error, "Could not get attributes for %s", pathname);
+ &path, pathname, git_repository_workdir(repo))) < 0 ||
+ (error = collect_attr_files(repo, pathname, &files)) < 0)
+ return error;
- if ((info = git__calloc(num_attr, sizeof(attr_get_many_info))) == NULL) {
- git__rethrow(GIT_ENOMEM, "Could not get attributes for %s", pathname);
- goto cleanup;
- }
+ info = git__calloc(num_attr, sizeof(attr_get_many_info));
+ GITERR_CHECK_ALLOC(info);
git_vector_foreach(&files, i, file) {
@@ -96,8 +92,6 @@ int git_attr_get_many(
}
pos = git_vector_bsearch(&rule->assigns, &info[k].name);
- git_clearerror(); /* okay if search failed */
-
if (pos >= 0) {
info[k].found = (git_attr_assignment *)
git_vector_get(&rule->assigns, pos);
@@ -133,15 +127,12 @@ int git_attr_foreach(
git_hashtable *seen = NULL;
if ((error = git_attr_path__init(
- &path, pathname, git_repository_workdir(repo))) < GIT_SUCCESS ||
- (error = collect_attr_files(repo, pathname, &files)) < GIT_SUCCESS)
- return git__rethrow(error, "Could not get attributes for %s", pathname);
+ &path, pathname, git_repository_workdir(repo))) < 0 ||
+ (error = collect_attr_files(repo, pathname, &files)) < 0)
+ return error;
seen = git_hashtable_alloc(8, git_hash__strhash_cb, git_hash__strcmp_cb);
- if (!seen) {
- error = GIT_ENOMEM;
- goto cleanup;
- }
+ GITERR_CHECK_ALLOC(seen);
git_vector_foreach(&files, i, file) {
@@ -152,25 +143,19 @@ int git_attr_foreach(
if (git_hashtable_lookup(seen, assign->name))
continue;
- error = git_hashtable_insert(seen, assign->name, assign);
- if (error != GIT_SUCCESS)
- goto cleanup;
+ if (!(error = git_hashtable_insert(seen, assign->name, assign)))
+ error = callback(assign->name, assign->value, payload);
- error = callback(assign->name, assign->value, payload);
- if (error != GIT_SUCCESS)
+ if (error != 0)
goto cleanup;
}
}
}
cleanup:
- if (seen)
- git_hashtable_free(seen);
+ git_hashtable_free(seen);
git_vector_free(&files);
- if (error != GIT_SUCCESS)
- (void)git__rethrow(error, "Could not get attributes for %s", pathname);
-
return error;
}
@@ -183,39 +168,35 @@ int git_attr_add_macro(
int error;
git_attr_rule *macro = NULL;
- if ((error = git_attr_cache__init(repo)) < GIT_SUCCESS)
- return error;
+ if (git_attr_cache__init(repo) < 0)
+ return -1;
macro = git__calloc(1, sizeof(git_attr_rule));
- if (!macro)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(macro);
macro->match.pattern = git__strdup(name);
- if (!macro->match.pattern) {
- git__free(macro);
- return GIT_ENOMEM;
- }
+ GITERR_CHECK_ALLOC(macro->match.pattern);
macro->match.length = strlen(macro->match.pattern);
macro->match.flags = GIT_ATTR_FNMATCH_MACRO;
error = git_attr_assignment__parse(repo, &macro->assigns, &values);
- if (error == GIT_SUCCESS)
+ if (!error)
error = git_attr_cache__insert_macro(repo, macro);
- if (error < GIT_SUCCESS)
+ if (error < 0)
git_attr_rule__free(macro);
return error;
}
-int git_attr_cache__is_cached(git_repository *repo, const char *path)
+bool git_attr_cache__is_cached(git_repository *repo, const char *path)
{
const char *cache_key = path;
if (repo && git__prefixcmp(cache_key, git_repository_workdir(repo)) == 0)
cache_key += strlen(git_repository_workdir(repo));
- return (git_hashtable_lookup(repo->attrcache.files, cache_key) == NULL);
+ return (git_hashtable_lookup(repo->attrcache.files, cache_key) != NULL);
}
int git_attr_cache__lookup_or_create_file(
@@ -229,29 +210,28 @@ int git_attr_cache__lookup_or_create_file(
git_attr_cache *cache = &repo->attrcache;
git_attr_file *file = NULL;
- file = git_hashtable_lookup(cache->files, key);
- if (file) {
+ if ((file = git_hashtable_lookup(cache->files, key)) != NULL) {
*file_ptr = file;
- return GIT_SUCCESS;
+ return 0;
}
if (loader && git_path_exists(filename) == false) {
*file_ptr = NULL;
- return GIT_SUCCESS;
+ return 0;
}
- if ((error = git_attr_file__new(&file)) < GIT_SUCCESS)
- return error;
+ if (git_attr_file__new(&file) < 0)
+ return -1;
if (loader)
error = loader(repo, filename, file);
else
error = git_attr_file__set_path(repo, key, file);
- if (error == GIT_SUCCESS)
+ if (!error)
error = git_hashtable_insert(cache->files, file->path, file);
- if (error < GIT_SUCCESS) {
+ if (error < 0) {
git_attr_file__free(file);
file = NULL;
}
@@ -274,8 +254,8 @@ int git_attr_cache__push_file(
const char *cache_key;
if (base != NULL) {
- if ((error = git_buf_joinpath(&path, base, filename)) < GIT_SUCCESS)
- return error;
+ if (git_buf_joinpath(&path, base, filename) < 0)
+ return -1;
filename = path.ptr;
}
@@ -287,7 +267,7 @@ int git_attr_cache__push_file(
error = git_attr_cache__lookup_or_create_file(
repo, cache_key, filename, loader, &file);
- if (error == GIT_SUCCESS && file != NULL)
+ if (!error && file != NULL)
error = git_vector_insert(stack, file);
git_buf_free(&path);
@@ -311,7 +291,7 @@ static int push_one_attr(void *ref, git_buf *path)
static int collect_attr_files(
git_repository *repo, const char *path, git_vector *files)
{
- int error = GIT_SUCCESS;
+ int error;
git_buf dir = GIT_BUF_INIT;
git_config *cfg;
const char *workdir = git_repository_workdir(repo);
@@ -342,7 +322,7 @@ static int collect_attr_files(
if (error < 0)
goto cleanup;
- if ((error = git_repository_config(&cfg, repo)) == GIT_SUCCESS) {
+ if (!(error = git_repository_config(&cfg, repo))) {
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 */
@@ -392,7 +372,7 @@ int git_attr_cache__init(git_repository *repo)
cache->initialized = 1;
/* insert default macros */
- return git_attr_add_macro(repo, "binary", "-diff -crlf");
+ return git_attr_add_macro(repo, "binary", "-diff -crlf -text");
}
void git_attr_cache_flush(
diff --git a/src/attr.h b/src/attr.h
index 5dbbb2366..eccda0ed7 100644
--- a/src/attr.h
+++ b/src/attr.h
@@ -34,7 +34,7 @@ extern int git_attr_cache__push_file(
const char *filename,
int (*loader)(git_repository *, const char *, git_attr_file *));
-/* returns GIT_SUCCESS if path is in cache */
-extern int git_attr_cache__is_cached(git_repository *repo, const char *path);
+/* returns true if path is in cache */
+extern bool git_attr_cache__is_cached(git_repository *repo, const char *path);
#endif
diff --git a/src/attr_file.c b/src/attr_file.c
index 35679ef22..646bd044c 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -287,7 +287,7 @@ int git_attr_path__init(
*/
/*
- * This will return GIT_SUCCESS if the spec was filled out,
+ * This will return 0 if the spec was filled out,
* GIT_ENOTFOUND if the fnmatch does not require matching, or
* another error code there was an actual problem.
*/
diff --git a/src/blob.c b/src/blob.c
index 20dcece74..f553de888 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -150,7 +150,7 @@ static int write_symlink(
int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path)
{
- int error = GIT_SUCCESS;
+ int error;
git_buf full_path = GIT_BUF_INIT;
git_off_t size;
struct stat st;
diff --git a/src/buffer.c b/src/buffer.c
index b0e329908..ec0302b9a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -17,8 +17,8 @@ char git_buf_initbuf[1];
static char git_buf__oom;
#define ENSURE_SIZE(b, d) \
- if ((d) > buf->asize && git_buf_grow(b, (d)) < GIT_SUCCESS)\
- return GIT_ENOMEM;
+ if ((d) > buf->asize && git_buf_grow(b, (d)) < 0)\
+ return -1;
void git_buf_init(git_buf *buf, size_t initial_size)
@@ -34,10 +34,8 @@ void git_buf_init(git_buf *buf, size_t initial_size)
int git_buf_grow(git_buf *buf, size_t target_size)
{
int error = git_buf_try_grow(buf, target_size);
- if (error != GIT_SUCCESS) {
+ if (error != 0)
buf->ptr = &git_buf__oom;
- }
-
return error;
}
@@ -47,10 +45,10 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
size_t new_size;
if (buf->ptr == &git_buf__oom)
- return GIT_ENOMEM;
+ return -1;
if (target_size <= buf->asize)
- return GIT_SUCCESS;
+ return 0;
if (buf->asize == 0) {
new_size = target_size;
@@ -80,7 +78,7 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
buf->size = buf->asize - 1;
buf->ptr[buf->size] = '\0';
- return GIT_SUCCESS;
+ return 0;
}
void git_buf_free(git_buf *buf)
@@ -117,7 +115,7 @@ int git_buf_set(git_buf *buf, const char *data, size_t len)
buf->size = len;
buf->ptr[buf->size] = '\0';
}
- return GIT_SUCCESS;
+ return 0;
}
int git_buf_sets(git_buf *buf, const char *string)
@@ -130,7 +128,7 @@ int git_buf_putc(git_buf *buf, char c)
ENSURE_SIZE(buf, buf->size + 2);
buf->ptr[buf->size++] = c;
buf->ptr[buf->size] = '\0';
- return GIT_SUCCESS;
+ return 0;
}
int git_buf_put(git_buf *buf, const char *data, size_t len)
@@ -139,7 +137,7 @@ int git_buf_put(git_buf *buf, const char *data, size_t len)
memmove(buf->ptr + buf->size, data, len);
buf->size += len;
buf->ptr[buf->size] = '\0';
- return GIT_SUCCESS;
+ return 0;
}
int git_buf_puts(git_buf *buf, const char *string)
@@ -163,7 +161,7 @@ int git_buf_printf(git_buf *buf, const char *format, ...)
if (len < 0) {
free(buf->ptr);
buf->ptr = &git_buf__oom;
- return GIT_ENOMEM;
+ return -1;
}
if ((size_t)len + 1 <= buf->asize - buf->size) {
@@ -174,7 +172,7 @@ int git_buf_printf(git_buf *buf, const char *format, ...)
ENSURE_SIZE(buf, buf->size + len + 1);
}
- return GIT_SUCCESS;
+ return 0;
}
void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
@@ -257,7 +255,7 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize)
int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
{
va_list ap;
- int i, error = GIT_SUCCESS;
+ int i;
size_t total_size = 0;
char *out;
@@ -284,8 +282,8 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
/* expand buffer if needed */
if (total_size > 0 &&
- (error = git_buf_grow(buf, buf->size + total_size + 1)) < GIT_SUCCESS)
- return error;
+ git_buf_grow(buf, buf->size + total_size + 1) < 0)
+ return -1;
out = buf->ptr + buf->size;
@@ -323,7 +321,7 @@ int git_buf_join_n(git_buf *buf, char separator, int nbuf, ...)
buf->size = out - buf->ptr;
buf->ptr[buf->size] = '\0';
- return error;
+ return 0;
}
int git_buf_join(
@@ -332,7 +330,6 @@ int git_buf_join(
const char *str_a,
const char *str_b)
{
- int error = GIT_SUCCESS;
size_t strlen_a = str_a ? strlen(str_a) : 0;
size_t strlen_b = strlen(str_b);
int need_sep = 0;
@@ -352,9 +349,8 @@ int git_buf_join(
if (str_a >= buf->ptr && str_a < buf->ptr + buf->size)
offset_a = str_a - buf->ptr;
- error = git_buf_grow(buf, strlen_a + strlen_b + need_sep + 1);
- if (error < GIT_SUCCESS)
- return error;
+ if (git_buf_grow(buf, strlen_a + strlen_b + need_sep + 1) < 0)
+ return -1;
/* fix up internal pointers */
if (offset_a >= 0)
@@ -370,7 +366,7 @@ int git_buf_join(
buf->size = strlen_a + strlen_b + need_sep;
buf->ptr[buf->size] = '\0';
- return error;
+ return 0;
}
void git_buf_rtrim(git_buf *buf)
diff --git a/src/buffer.h b/src/buffer.h
index d90db4d4a..294ff6961 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -32,7 +32,7 @@ void git_buf_init(git_buf *buf, size_t initial_size);
* If the allocation fails, this will return an error and the buffer
* will be marked as invalid for future operations. The existing
* contents of the buffer will be preserved however.
- * @return GIT_SUCCESS or GIT_ENOMEM on failure
+ * @return 0 on success or -1 on failure
*/
int git_buf_grow(git_buf *buf, size_t target_size);
@@ -63,12 +63,12 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
bool git_buf_oom(const git_buf *buf);
/*
- * The functions below that return int values, will return GIT_ENOMEM
- * if they fail to expand the git_buf when they are called, otherwise
- * GIT_SUCCESS. Passing a git_buf that has failed an allocation will
- * automatically return GIT_ENOMEM for all further calls. As a result,
- * you can ignore the return code of these functions and call them in a
- * series then just call git_buf_lasterror at the end.
+ * Functions below that return int value error codes will return 0 on
+ * success or -1 on failure (which generally means an allocation failed).
+ * Using a git_buf where the allocation has failed with result in -1 from
+ * all further calls using that buffer. As a result, you can ignore the
+ * return code of these functions and call them in a series then just call
+ * git_buf_oom at the end.
*/
int git_buf_set(git_buf *buf, const char *data, size_t len);
int git_buf_sets(git_buf *buf, const char *string);
@@ -86,7 +86,7 @@ int git_buf_join(git_buf *buf, char separator, const char *str_a, const char *st
/**
* Join two strings as paths, inserting a slash between as needed.
- * @return error code or GIT_SUCCESS
+ * @return 0 on success, -1 on failure
*/
GIT_INLINE(int) git_buf_joinpath(git_buf *buf, const char *a, const char *b)
{
diff --git a/src/cache.c b/src/cache.c
index 9e566792a..f445e906d 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -32,11 +32,10 @@ int git_cache_init(git_cache *cache, size_t size, git_cached_obj_freeptr free_pt
git_mutex_init(&cache->lock);
cache->nodes = git__malloc(size * sizeof(git_cached_obj *));
- if (cache->nodes == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(cache->nodes);
memset(cache->nodes, 0x0, size * sizeof(git_cached_obj *));
- return GIT_SUCCESS;
+ return 0;
}
void git_cache_free(git_cache *cache)
diff --git a/src/diff.c b/src/diff.c
index 06c61122a..69c944c63 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -249,14 +249,14 @@ static git_diff_list *git_diff_list_alloc(
diff->opts.dst_prefix = swap;
}
- if (git_vector_init(&diff->deltas, 0, diff_delta__cmp) < GIT_SUCCESS) {
+ if (git_vector_init(&diff->deltas, 0, diff_delta__cmp) < 0) {
git__free(diff->opts.src_prefix);
git__free(diff->opts.dst_prefix);
git__free(diff);
return NULL;
}
- /* do something safe with the pathspec strarray */
+ /* TODO: do something safe with the pathspec strarray */
return diff;
}
diff --git a/src/filebuf.c b/src/filebuf.c
index 09b1e0e59..a9de165d5 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -91,7 +91,7 @@ static int lock_file(git_filebuf *file, int flags)
p_close(source);
}
- return GIT_SUCCESS;
+ return 0;
}
void git_filebuf_cleanup(git_filebuf *file)
diff --git a/src/fileops.c b/src/fileops.c
index aa52b09d7..65942adf5 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -208,13 +208,19 @@ int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
int git_futils_mmap_ro_file(git_map *out, const char *path)
{
- git_file fd = p_open(path, O_RDONLY /* | O_NOATIME */);
- git_off_t len = git_futils_filesize(fd);
+ git_file fd = git_futils_open_ro(path);
+ git_off_t len;
int result;
+
+ if (fd < 0)
+ return fd;
+
+ len = git_futils_filesize(fd);
if (!git__is_sizet(len)) {
giterr_set(GITERR_OS, "File `%s` too large to mmap", path);
return -1;
}
+
result = git_futils_mmap_ro(out, fd, 0, (size_t)len);
p_close(fd);
return result;
diff --git a/src/fileops.h b/src/fileops.h
index 6df565321..865b3c9b0 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -26,7 +26,7 @@ extern int git_futils_readbuffer_updated(git_buf *obj, const char *path, time_t
* These are custom filesystem-related helper methods. They are
* rather high level, and wrap the underlying POSIX methods
*
- * All these methods return GIT_SUCCESS on success,
+ * All these methods return 0 on success,
* or an error code on failure and an error message is set.
*/
@@ -108,8 +108,8 @@ extern mode_t git_futils_canonical_mode(mode_t raw_mode);
* @param begin first byte to map, this should be page aligned.
* @param end number of bytes to map.
* @return
- * - GIT_SUCCESS on success;
- * - GIT_EOSERR on an unspecified OS related error.
+ * - 0 on success;
+ * - -1 on error.
*/
extern int git_futils_mmap_ro(
git_map *out,
@@ -123,8 +123,9 @@ extern int git_futils_mmap_ro(
* @param out buffer to populate with the mapping information.
* @param path path to file to be opened.
* @return
- * - GIT_SUCCESS on success;
- * - GIT_EOSERR on an unspecified OS related error.
+ * - 0 on success;
+ * - GIT_ENOTFOUND if not found;
+ * - -1 on an unspecified OS related error.
*/
extern int git_futils_mmap_ro_file(
git_map *out,
@@ -142,9 +143,9 @@ extern void git_futils_mmap_free(git_map *map);
* @param pathbuf buffer to write the full path into
* @param filename name of file to find in the home directory
* @return
- * - GIT_SUCCESS if found;
+ * - 0 if found;
* - GIT_ENOTFOUND if not found;
- * - GIT_EOSERR on an unspecified OS related error.
+ * - -1 on an unspecified OS related error.
*/
extern int git_futils_find_global_file(git_buf *path, const char *filename);
@@ -154,9 +155,9 @@ extern int git_futils_find_global_file(git_buf *path, const char *filename);
* @param pathbuf buffer to write the full path into
* @param filename name of file to find in the home directory
* @return
- * - GIT_SUCCESS if found;
+ * - 0 if found;
* - GIT_ENOTFOUND if not found;
- * - GIT_EOSERR on an unspecified OS related error.
+ * - -1 on an unspecified OS related error.
*/
extern int git_futils_find_system_file(git_buf *path, const char *filename);
diff --git a/src/ignore.c b/src/ignore.c
index 4cbc55d4b..be00efd1b 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -10,30 +10,31 @@
static int load_ignore_file(
git_repository *repo, const char *path, git_attr_file *ignores)
{
- int error = GIT_SUCCESS;
+ int error;
git_buf fbuf = GIT_BUF_INIT;
git_attr_fnmatch *match = NULL;
const char *scan = NULL;
char *context = NULL;
- if (ignores->path == NULL)
- error = git_attr_file__set_path(repo, path, ignores);
+ if (ignores->path == NULL) {
+ if (git_attr_file__set_path(repo, path, ignores) < 0)
+ return -1;
+ }
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;
+ GITERR_CHECK_ALLOC(context);
}
- if (error == GIT_SUCCESS)
- error = git_futils_readbuffer(&fbuf, path);
+ error = git_futils_readbuffer(&fbuf, path);
scan = fbuf.ptr;
- while (error == GIT_SUCCESS && *scan) {
- if (!match && !(match = git__calloc(1, sizeof(git_attr_fnmatch)))) {
- error = GIT_ENOMEM;
- break;
+ while (!error && *scan) {
+ if (!match) {
+ match = git__calloc(1, sizeof(*match));
+ GITERR_CHECK_ALLOC(match);
}
if (!(error = git_attr_fnmatch__parse(match, context, &scan))) {
@@ -42,12 +43,12 @@ static int load_ignore_file(
error = git_vector_insert(&ignores->rules, match);
}
- if (error != GIT_SUCCESS) {
+ if (error != 0) {
git__free(match->pattern);
match->pattern = NULL;
if (error == GIT_ENOTFOUND)
- error = GIT_SUCCESS;
+ error = 0;
} else {
match = NULL; /* vector now "owns" the match */
}
@@ -57,9 +58,6 @@ static int load_ignore_file(
git__free(match);
git__free(context);
- if (error != GIT_SUCCESS)
- git__rethrow(error, "Could not open ignore file '%s'", path);
-
return error;
}
@@ -74,7 +72,7 @@ static int push_one_ignore(void *ref, git_buf *path)
int git_ignore__for_path(git_repository *repo, const char *path, git_ignores *ignores)
{
- int error = GIT_SUCCESS;
+ int error = 0;
git_config *cfg;
const char *workdir = git_repository_workdir(repo);
@@ -83,63 +81,59 @@ int git_ignore__for_path(git_repository *repo, const char *path, git_ignores *ig
ignores->repo = repo;
git_buf_init(&ignores->dir, 0);
ignores->ign_internal = NULL;
- git_vector_init(&ignores->ign_path, 8, NULL);
- git_vector_init(&ignores->ign_global, 2, NULL);
- if ((error = git_attr_cache__init(repo)) < GIT_SUCCESS)
+ if ((error = git_vector_init(&ignores->ign_path, 8, NULL)) < 0 ||
+ (error = git_vector_init(&ignores->ign_global, 2, NULL)) < 0 ||
+ (error = git_attr_cache__init(repo)) < 0)
goto cleanup;
- if ((error = git_path_find_dir(&ignores->dir, path, workdir)) < GIT_SUCCESS)
+ /* translate path into directory within workdir */
+ if ((error = git_path_find_dir(&ignores->dir, path, workdir)) < 0)
goto cleanup;
/* set up internals */
error = git_attr_cache__lookup_or_create_file(
repo, GIT_IGNORE_INTERNAL, NULL, NULL, &ignores->ign_internal);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
/* load .gitignore up the path */
error = git_path_walk_up(&ignores->dir, workdir, push_one_ignore, ignores);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
/* load .git/info/exclude */
error = push_ignore(repo, &ignores->ign_global,
repo->path_repository, GIT_IGNORE_FILE_INREPO);
- if (error < GIT_SUCCESS)
+ if (error < 0)
goto cleanup;
/* load core.excludesfile */
- if ((error = git_repository_config(&cfg, repo)) == GIT_SUCCESS) {
+ if ((error = git_repository_config(&cfg, repo)) == 0) {
const char *core_ignore;
error = git_config_get_string(cfg, GIT_IGNORE_CONFIG, &core_ignore);
- if (error == GIT_SUCCESS && core_ignore != NULL)
+ if (error == 0 && core_ignore != NULL)
error = push_ignore(repo, &ignores->ign_global, NULL, core_ignore);
else {
- error = GIT_SUCCESS;
- git_clearerror(); /* don't care if attributesfile is not set */
+ error = 0;
+ giterr_clear(); /* don't care if attributesfile is not set */
}
git_config_free(cfg);
}
cleanup:
- if (error < GIT_SUCCESS) {
+ if (error < 0)
git_ignore__free(ignores);
- git__rethrow(error, "Could not get ignore files for '%s'", path);
- }
-
return error;
}
int git_ignore__push_dir(git_ignores *ign, const char *dir)
{
- int error = git_buf_joinpath(&ign->dir, ign->dir.ptr, dir);
-
- if (error == GIT_SUCCESS)
- error = push_ignore(
+ if (git_buf_joinpath(&ign->dir, ign->dir.ptr, dir) < 0)
+ return -1;
+ else
+ return push_ignore(
ign->repo, &ign->ign_path, ign->dir.ptr, GIT_IGNORE_FILE);
-
- return error;
}
int git_ignore__pop_dir(git_ignores *ign)
@@ -150,7 +144,7 @@ int git_ignore__pop_dir(git_ignores *ign)
git_vector_pop(&ign->ign_path);
git_buf_rtruncate_at_char(&ign->dir, '/');
}
- return GIT_SUCCESS;
+ return 0;
}
void git_ignore__free(git_ignores *ignores)
@@ -161,7 +155,7 @@ void git_ignore__free(git_ignores *ignores)
git_buf_free(&ignores->dir);
}
-static int ignore_lookup_in_rules(
+static bool ignore_lookup_in_rules(
git_vector *rules, git_attr_path *path, int *ignored)
{
unsigned int j;
@@ -170,45 +164,40 @@ static int ignore_lookup_in_rules(
git_vector_rforeach(rules, j, match) {
if (git_attr_fnmatch__match(match, path)) {
*ignored = ((match->flags & GIT_ATTR_FNMATCH_NEGATIVE) == 0);
- return 0;
+ return true;
}
}
- return GIT_ENOTFOUND;
+ return false;
}
int git_ignore__lookup(git_ignores *ignores, const char *pathname, int *ignored)
{
- int error;
unsigned int i;
git_attr_file *file;
git_attr_path path;
- if ((error = git_attr_path__init(
- &path, pathname, git_repository_workdir(ignores->repo))) < GIT_SUCCESS)
- return git__rethrow(error, "Could not get attribute for '%s'", pathname);
+ if (git_attr_path__init(
+ &path, pathname, git_repository_workdir(ignores->repo)) < 0)
+ return -1;
- /* first process builtins */
- error = ignore_lookup_in_rules(
- &ignores->ign_internal->rules, &path, ignored);
- if (error == GIT_SUCCESS)
- return error;
+ /* first process builtins - success means path was found */
+ if (ignore_lookup_in_rules(
+ &ignores->ign_internal->rules, &path, ignored))
+ return 0;
/* next process files in the path */
git_vector_foreach(&ignores->ign_path, i, file) {
- error = ignore_lookup_in_rules(&file->rules, &path, ignored);
- if (error == GIT_SUCCESS)
- return error;
+ if (ignore_lookup_in_rules(&file->rules, &path, ignored))
+ return 0;
}
/* last process global ignores */
git_vector_foreach(&ignores->ign_global, i, file) {
- error = ignore_lookup_in_rules(&file->rules, &path, ignored);
- if (error == GIT_SUCCESS)
- return error;
+ if (ignore_lookup_in_rules(&file->rules, &path, ignored))
+ return 0;
}
*ignored = 0;
-
- return GIT_SUCCESS;
+ return 0;
}
diff --git a/src/iterator.c b/src/iterator.c
index c10b9ffc2..5cc01ccbc 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -34,25 +34,24 @@ static const git_tree_entry *tree_iterator__tree_entry(tree_iterator *ti)
static int tree_iterator__current(
git_iterator *self, const git_index_entry **entry)
{
- int error;
tree_iterator *ti = (tree_iterator *)self;
const git_tree_entry *te = tree_iterator__tree_entry(ti);
*entry = NULL;
if (te == NULL)
- return GIT_SUCCESS;
+ return 0;
ti->entry.mode = te->attr;
git_oid_cpy(&ti->entry.oid, &te->oid);
- error = git_buf_joinpath(&ti->path, ti->path.ptr, te->filename);
- if (error < GIT_SUCCESS)
- return error;
+ if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
+ return -1;
+
ti->entry.path = ti->path.ptr;
*entry = &ti->entry;
- return GIT_SUCCESS;
+ return 0;
}
static int tree_iterator__at_end(git_iterator *self)
@@ -63,7 +62,8 @@ static int tree_iterator__at_end(git_iterator *self)
static tree_iterator_frame *tree_iterator__alloc_frame(git_tree *tree)
{
tree_iterator_frame *tf = git__calloc(1, sizeof(tree_iterator_frame));
- tf->tree = tree;
+ if (tf != NULL)
+ tf->tree = tree;
return tf;
}
@@ -75,24 +75,22 @@ static int tree_iterator__expand_tree(tree_iterator *ti)
tree_iterator_frame *tf;
while (te != NULL && entry_is_tree(te)) {
- error = git_tree_lookup(&subtree, ti->repo, &te->oid);
- if (error != GIT_SUCCESS)
+ if ((error = git_tree_lookup(&subtree, ti->repo, &te->oid)) < 0)
return error;
if ((tf = tree_iterator__alloc_frame(subtree)) == NULL)
- return GIT_ENOMEM;
+ return -1;
tf->next = ti->stack;
ti->stack = tf;
- error = git_buf_joinpath(&ti->path, ti->path.ptr, te->filename);
- if (error < GIT_SUCCESS)
- return error;
+ if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
+ return -1;
te = tree_iterator__tree_entry(ti);
}
- return GIT_SUCCESS;
+ return 0;
}
static void tree_iterator__pop_frame(tree_iterator *ti)
@@ -107,7 +105,7 @@ static void tree_iterator__pop_frame(tree_iterator *ti)
static int tree_iterator__advance(
git_iterator *self, const git_index_entry **entry)
{
- int error = GIT_SUCCESS;
+ int error = 0;
tree_iterator *ti = (tree_iterator *)self;
const git_tree_entry *te = NULL;
@@ -129,7 +127,7 @@ static int tree_iterator__advance(
if (te && entry_is_tree(te))
error = tree_iterator__expand_tree(ti);
- if (error == GIT_SUCCESS && entry != NULL)
+ if (!error && entry != NULL)
error = tree_iterator__current(self, entry);
return error;
@@ -158,8 +156,7 @@ int git_iterator_for_tree(
{
int error;
tree_iterator *ti = git__calloc(1, sizeof(tree_iterator));
- if (!ti)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(ti);
ti->base.type = GIT_ITERATOR_TREE;
ti->base.current = tree_iterator__current;
@@ -170,11 +167,10 @@ int git_iterator_for_tree(
ti->repo = repo;
ti->stack = tree_iterator__alloc_frame(tree);
- if ((error = tree_iterator__expand_tree(ti)) < GIT_SUCCESS)
+ if ((error = tree_iterator__expand_tree(ti)) < 0)
git_iterator_free((git_iterator *)ti);
else
*iter = (git_iterator *)ti;
-
return error;
}
@@ -190,7 +186,7 @@ static int index_iterator__current(
{
index_iterator *ii = (index_iterator *)self;
*entry = git_index_get(ii->index, ii->current);
- return GIT_SUCCESS;
+ return 0;
}
static int index_iterator__at_end(git_iterator *self)
@@ -207,14 +203,14 @@ static int index_iterator__advance(
ii->current++;
if (entry)
*entry = git_index_get(ii->index, ii->current);
- return GIT_SUCCESS;
+ return 0;
}
static int index_iterator__reset(git_iterator *self)
{
index_iterator *ii = (index_iterator *)self;
ii->current = 0;
- return GIT_SUCCESS;
+ return 0;
}
static void index_iterator__free(git_iterator *self)
@@ -228,8 +224,7 @@ int git_iterator_for_index(git_repository *repo, git_iterator **iter)
{
int error;
index_iterator *ii = git__calloc(1, sizeof(index_iterator));
- if (!ii)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(ii);
ii->base.type = GIT_ITERATOR_INDEX;
ii->base.current = index_iterator__current;
@@ -239,7 +234,7 @@ int git_iterator_for_index(git_repository *repo, git_iterator **iter)
ii->base.free = index_iterator__free;
ii->current = 0;
- if ((error = git_repository_index(&ii->index, repo)) < GIT_SUCCESS)
+ if ((error = git_repository_index(&ii->index, repo)) < 0)
git__free(ii);
else
*iter = (git_iterator *)ii;
@@ -269,8 +264,8 @@ static workdir_iterator_frame *workdir_iterator__alloc_frame(void)
{
workdir_iterator_frame *wf = git__calloc(1, sizeof(workdir_iterator_frame));
if (wf == NULL)
- return wf;
- if (git_vector_init(&wf->entries, 0, git_path_with_stat_cmp) != GIT_SUCCESS) {
+ return NULL;
+ if (git_vector_init(&wf->entries, 0, git_path_with_stat_cmp) != 0) {
git__free(wf);
return NULL;
}
@@ -294,11 +289,10 @@ static int workdir_iterator__expand_dir(workdir_iterator *wi)
{
int error;
workdir_iterator_frame *wf = workdir_iterator__alloc_frame();
- if (wf == NULL)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(wf);
error = git_path_dirload_with_stat(wi->path.ptr, wi->root_len, &wf->entries);
- if (error < GIT_SUCCESS || wf->entries.length == 0) {
+ if (error < 0 || wf->entries.length == 0) {
workdir_iterator__free_frame(wf);
return GIT_ENOTFOUND;
}
@@ -321,7 +315,7 @@ static int workdir_iterator__current(
{
workdir_iterator *wi = (workdir_iterator *)self;
*entry = (wi->entry.path == NULL) ? NULL : &wi->entry;
- return GIT_SUCCESS;
+ return 0;
}
static int workdir_iterator__at_end(git_iterator *self)
@@ -341,7 +335,7 @@ static int workdir_iterator__advance(
*entry = NULL;
if (wi->entry.path == NULL)
- return GIT_SUCCESS;
+ return 0;
while ((wf = wi->stack) != NULL) {
next = git_vector_get(&wf->entries, ++wf->index);
@@ -359,13 +353,13 @@ static int workdir_iterator__advance(
if (wi->stack == NULL) {
memset(&wi->entry, 0, sizeof(wi->entry));
- return GIT_SUCCESS;
+ return 0;
}
}
error = workdir_iterator__update_entry(wi);
- if (error == GIT_SUCCESS && entry != NULL)
+ if (!error && entry != NULL)
error = workdir_iterator__current(self, entry);
return error;
@@ -382,7 +376,7 @@ static int workdir_iterator__reset(git_iterator *self)
}
if (wi->stack)
wi->stack->index = 0;
- return GIT_SUCCESS;
+ return 0;
}
static void workdir_iterator__free(git_iterator *self)
@@ -405,9 +399,8 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
git_path_with_stat *ps = git_vector_get(&wi->stack->entries, wi->stack->index);
git_buf_truncate(&wi->path, wi->root_len);
- error = git_buf_put(&wi->path, ps->path, ps->path_len);
- if (error < GIT_SUCCESS)
- return error;
+ if (git_buf_put(&wi->path, ps->path, ps->path_len) < 0)
+ return -1;
memset(&wi->entry, 0, sizeof(wi->entry));
wi->entry.path = ps->path;
@@ -431,27 +424,26 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
/* if this is a file type we don't handle, treat as ignored */
if (wi->entry.mode == 0)
- return GIT_SUCCESS;
+ return 0;
/* okay, we are far enough along to look up real ignore rule */
error = git_ignore__lookup(&wi->ignores, wi->entry.path, &wi->is_ignored);
- if (error != GIT_SUCCESS)
- return GIT_SUCCESS;
+ if (error < 0)
+ return 0;
/* detect submodules */
if (S_ISDIR(wi->entry.mode) &&
git_path_contains(&wi->path, DOT_GIT) == true)
wi->entry.mode = S_IFGITLINK;
- return GIT_SUCCESS;
+ return 0;
}
int git_iterator_for_workdir(git_repository *repo, git_iterator **iter)
{
int error;
workdir_iterator *wi = git__calloc(1, sizeof(workdir_iterator));
- if (!wi)
- return GIT_ENOMEM;
+ GITERR_CHECK_ALLOC(wi);
wi->base.type = GIT_ITERATOR_WORKDIR;
wi->base.current = workdir_iterator__current;
@@ -461,19 +453,17 @@ int git_iterator_for_workdir(git_repository *repo, git_iterator **iter)
wi->base.free = workdir_iterator__free;
wi->repo = repo;
- error = git_buf_sets(&wi->path, git_repository_workdir(repo));
- if (error == GIT_SUCCESS)
- error = git_path_to_dir(&wi->path);
- if (error == GIT_SUCCESS)
- error = git_ignore__for_path(repo, "", &wi->ignores);
- if (error != GIT_SUCCESS) {
+ if (git_buf_sets(&wi->path, git_repository_workdir(repo)) < 0 ||
+ git_path_to_dir(&wi->path) < 0 ||
+ git_ignore__for_path(repo, "", &wi->ignores) < 0)
+ {
git__free(wi);
- return error;
+ return -1;
}
wi->root_len = wi->path.size;
- if ((error = workdir_iterator__expand_dir(wi)) < GIT_SUCCESS)
+ if ((error = workdir_iterator__expand_dir(wi)) < 0)
git_iterator_free((git_iterator *)wi);
else
*iter = (git_iterator *)wi;
@@ -487,7 +477,7 @@ int git_iterator_current_tree_entry(
{
*tree_entry = (iter->type != GIT_ITERATOR_TREE) ? NULL :
tree_iterator__tree_entry((tree_iterator *)iter);
- return GIT_SUCCESS;
+ return 0;
}
int git_iterator_current_is_ignored(git_iterator *iter)
@@ -504,10 +494,10 @@ int git_iterator_advance_into_directory(
if (iter->type == GIT_ITERATOR_WORKDIR &&
wi->entry.path && S_ISDIR(wi->entry.mode))
{
- if (workdir_iterator__expand_dir(wi) < GIT_SUCCESS)
+ if (workdir_iterator__expand_dir(wi) < 0)
/* if error loading or if empty, skip the directory. */
return workdir_iterator__advance(iter, entry);
}
- return entry ? git_iterator_current(iter, entry) : GIT_SUCCESS;
+ return entry ? git_iterator_current(iter, entry) : 0;
}
diff --git a/src/mwindow.c b/src/mwindow.c
index cde24d1b1..7fe02b9ce 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -115,7 +115,7 @@ static int git_mwindow_close_lru(git_mwindow_file *mwf)
unsigned int i;
git_mwindow *lru_w = NULL, *lru_l = NULL, **list = &mwf->windows;
- /* FIMXE: Does this give us any advantage? */
+ /* FIXME: Does this give us any advantage? */
if(mwf->windows)
git_mwindow_scan_lru(mwf, &lru_w, &lru_l);
@@ -127,22 +127,23 @@ static int git_mwindow_close_lru(git_mwindow_file *mwf)
list = &cur->windows;
}
- if (lru_w) {
- ctl->mapped -= lru_w->window_map.len;
- git_futils_mmap_free(&lru_w->window_map);
+ if (!lru_w) {
+ giterr_set(GITERR_OS, "Failed to close memory window. Couldn't find LRU");
+ return -1;
+ }
- if (lru_l)
- lru_l->next = lru_w->next;
- else
- *list = lru_w->next;
+ ctl->mapped -= lru_w->window_map.len;
+ git_futils_mmap_free(&lru_w->window_map);
- git__free(lru_w);
- ctl->open_windows--;
+ if (lru_l)
+ lru_l->next = lru_w->next;
+ else
+ *list = lru_w->next;
- return GIT_SUCCESS;
- }
+ git__free(lru_w);
+ ctl->open_windows--;
- return git__throw(GIT_ERROR, "Failed to close memory window. Couln't find LRU");
+ return 0;
}
static git_mwindow *new_window(
@@ -158,7 +159,7 @@ static git_mwindow *new_window(
w = git__malloc(sizeof(*w));
if (w == NULL)
- return w;
+ return NULL;
memset(w, 0x0, sizeof(*w));
w->offset = (offset / walign) * walign;
@@ -170,7 +171,7 @@ static git_mwindow *new_window(
ctl->mapped += (size_t)len;
while (_mw_options.mapped_limit < ctl->mapped &&
- git_mwindow_close_lru(mwf) == GIT_SUCCESS) /* nop */;
+ git_mwindow_close_lru(mwf) == 0) /* nop */;
/*
* We treat _mw_options.mapped_limit as a soft limit. If we can't find a
diff --git a/src/odb_loose.c b/src/odb_loose.c
index c493cc60b..085df428a 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -582,7 +582,7 @@ static int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_
{
git_buf object_path = GIT_BUF_INIT;
git_rawobj raw;
- int error = GIT_SUCCESS;
+ int error;
assert(backend && oid);
@@ -803,7 +803,7 @@ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const v
error = -1;
cleanup:
- if (error < GIT_SUCCESS)
+ if (error < 0)
git_filebuf_cleanup(&fbuf);
git_buf_free(&final_path);
return error;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 7add3718a..1a1fa55c5 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -226,7 +226,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
error = git_packfile_check(&pack, path->ptr);
if (error == GIT_ENOTFOUND)
/* ignore missing .pack file as git does */
- return GIT_SUCCESS;
+ return 0;
else if (error < 0)
return error;
diff --git a/src/pack.c b/src/pack.c
index 40b3ca77c..a4e506945 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -508,7 +508,7 @@ static int packfile_open(struct git_pack_file *p)
assert(p->index_map.data);
- if (!p->index_map.data && pack_index_open(p) < GIT_SUCCESS)
+ if (!p->index_map.data && pack_index_open(p) < 0)
return git_odb__error_notfound("failed to open packfile");
/* TODO: open with noatime */
diff --git a/src/path.c b/src/path.c
index 45cc94e82..31d2e72f9 100644
--- a/src/path.c
+++ b/src/path.c
@@ -327,7 +327,7 @@ int git_path_walk_up(
assert(path && cb);
if (ceiling != NULL) {
- if (git__prefixcmp(path->ptr, ceiling) == GIT_SUCCESS)
+ if (git__prefixcmp(path->ptr, ceiling) == 0)
stop = (ssize_t)strlen(ceiling);
else
stop = path->size;
diff --git a/src/path.h b/src/path.h
index 3cf73940e..eb397d17a 100644
--- a/src/path.h
+++ b/src/path.h
@@ -139,7 +139,7 @@ extern int git_path_lstat(const char *path, struct stat *st);
*
* @param dir Directory to check.
* @param item Item that might be in the directory.
- * @return GIT_SUCCESS if item exists in directory, <0 otherwise.
+ * @return 0 if item exists in directory, <0 otherwise.
*/
extern bool git_path_contains(git_buf *dir, const char *item);
@@ -211,7 +211,7 @@ extern int git_path_cmp(
* Invoke callback up path directory by directory until the ceiling is
* reached (inclusive of a final call at the root_path).
*
- * Returning anything other than GIT_SUCCESS from the callback function
+ * Returning anything other than 0 from the callback function
* will stop the iteration and propogate the error to the caller.
*
* @param pathbuf Buffer the function reads the directory from and
diff --git a/src/refs.c b/src/refs.c
index b4c4b1ec1..ed364cf90 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -186,7 +186,7 @@ static int loose_parse_oid(git_oid *oid, git_buf *file_content)
if (*buffer != '\n')
goto corrupt;
- return GIT_SUCCESS;
+ return 0;
corrupt:
giterr_set(GITERR_REFERENCE, "Corrupted loose reference file");
@@ -200,7 +200,7 @@ static git_rtype loose_guess_rtype(const git_buf *full_path)
type = GIT_REF_INVALID;
- if (git_futils_readbuffer(&ref_file, full_path->ptr) == GIT_SUCCESS) {
+ if (git_futils_readbuffer(&ref_file, full_path->ptr) == 0) {
if (git__prefixcmp((const char *)(ref_file.ptr), GIT_SYMREF) == 0)
type = GIT_REF_SYMBOLIC;
else
@@ -335,7 +335,7 @@ static int packed_parse_peel(
goto corrupt;
/* Is this a valid object id? */
- if (git_oid_fromstr(&tag_ref->peel, buffer) < GIT_SUCCESS)
+ if (git_oid_fromstr(&tag_ref->peel, buffer) < 0)
goto corrupt;
buffer = buffer + GIT_OID_HEXSZ;
@@ -1483,7 +1483,7 @@ int git_reference_listall(
array->strings = NULL;
array->count = 0;
- if (git_vector_init(&ref_list, 8, NULL) < GIT_SUCCESS)
+ if (git_vector_init(&ref_list, 8, NULL) < 0)
return -1;
if (git_reference_foreach(
diff --git a/src/repository.c b/src/repository.c
index 99eee52ea..45bedcbe0 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -878,7 +878,7 @@ int git_repository_set_workdir(git_repository *repo, const char *workdir)
GITERR_CHECK_ALLOC(repo->workdir);
repo->is_bare = 0;
- return GIT_SUCCESS;
+ return 0;
}
int git_repository_is_bare(git_repository *repo)
diff --git a/src/status.c b/src/status.c
index 6315d6355..2221db3d9 100644
--- a/src/status.c
+++ b/src/status.c
@@ -76,15 +76,17 @@ static int status_entry_update_from_workdir(struct status_entry *e, const char*
{
struct stat filest;
- if (p_stat(full_path, &filest) < GIT_SUCCESS)
- return git__throw(GIT_EOSERR, "Failed to determine status of file '%s'. Can't read file", full_path);
+ if (p_stat(full_path, &filest) < 0) {
+ giterr_set(GITERR_OS, "Cannot access file '%s'", full_path);
+ return GIT_ENOTFOUND;
+ }
if (e->mtime.seconds == (git_time_t)filest.st_mtime)
git_oid_cpy(&e->wt_oid, &e->index_oid);
else
git_odb_hashfile(&e->wt_oid, full_path, GIT_OBJ_BLOB);
- return GIT_SUCCESS;
+ return 0;
}
static int status_entry_update_flags(struct status_entry *e)
@@ -115,7 +117,7 @@ static int status_entry_update_flags(struct status_entry *e)
else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0)
e->status_flags |= GIT_STATUS_WT_MODIFIED;
- return GIT_SUCCESS;
+ return 0;
}
static int status_entry_is_ignorable(struct status_entry *e)
@@ -126,14 +128,17 @@ static int status_entry_is_ignorable(struct status_entry *e)
static int status_entry_update_ignore(struct status_entry *e, git_ignores *ignores, const char *path)
{
- int error, ignored;
+ int ignored;
- if ((error = git_ignore__lookup(ignores, path, &ignored)) == GIT_SUCCESS &&
- ignored)
+ if (git_ignore__lookup(ignores, path, &ignored) < 0)
+ return -1;
+
+ if (ignored)
+ /* toggle off WT_NEW and on IGNORED */
e->status_flags =
(e->status_flags & ~GIT_STATUS_WT_NEW) | GIT_STATUS_IGNORED;
- return error;
+ return 0;
}
struct status_st {
@@ -156,33 +161,28 @@ static int retrieve_head_tree(git_tree **tree_out, git_repository *repo)
git_reference *resolved_head_ref;
git_commit *head_commit = NULL;
git_tree *tree;
- int error = GIT_SUCCESS;
+ int error = 0;
*tree_out = NULL;
- error = git_repository_head(&resolved_head_ref, repo);
- /*
- * We assume that a situation where HEAD exists but can not be resolved is valid.
- * A new repository fits this description for instance.
- */
- if (error == GIT_ENOTFOUND)
- return GIT_SUCCESS;
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "HEAD can't be resolved");
+ if ((error = git_repository_head(&resolved_head_ref, repo)) < 0) {
+ /* Assume that a situation where HEAD exists but can not be resolved
+ * is valid. A new repository fits this description for instance.
+ */
+ if (error == GIT_ENOTFOUND)
+ return 0;
+ return error;
+ }
- if ((error = git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref))) < GIT_SUCCESS)
- return git__rethrow(error, "The tip of HEAD can't be retrieved");
+ if ((error = git_commit_lookup(
+ &head_commit, repo, git_reference_oid(resolved_head_ref))) < 0)
+ return error;
git_reference_free(resolved_head_ref);
- if ((error = git_commit_tree(&tree, head_commit)) < GIT_SUCCESS) {
- error = git__rethrow(error, "The tree of HEAD can't be retrieved");
- goto exit;
- }
-
- *tree_out = tree;
+ if ((error = git_commit_tree(&tree, head_commit)) == 0)
+ *tree_out = tree;
-exit:
git_commit_free(head_commit);
return error;
}
@@ -231,7 +231,8 @@ static int process_folder(
break;
default:
- return git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type");
+ giterr_set(GITERR_REPOSITORY, "Unexpected tree entry type");
+ return -1;
}
}
@@ -240,7 +241,7 @@ static int process_folder(
git_ignores ignores, *old_ignores;
if ((error = git_ignore__for_path(st->repo,
- full_path->ptr + st->workdir_path_len, &ignores)) == GIT_SUCCESS)
+ full_path->ptr + st->workdir_path_len, &ignores)) == 0)
{
old_ignores = st->ignores;
st->ignores = &ignores;
@@ -267,17 +268,17 @@ static int process_folder(
static int store_if_changed(struct status_st *st, struct status_entry *e)
{
- int error;
- if ((error = status_entry_update_flags(e)) < GIT_SUCCESS)
- return git__throw(error, "Failed to process the file '%s'. It doesn't exist in the workdir, in the HEAD nor in the index", e->path);
+ int error = status_entry_update_flags(e);
+ if (error < 0)
+ return error;
if (status_entry_is_ignorable(e) &&
- (error = status_entry_update_ignore(e, st->ignores, e->path)) < GIT_SUCCESS)
+ (error = status_entry_update_ignore(e, st->ignores, e->path)) < 0)
return error;
if (e->status_flags == GIT_STATUS_CURRENT) {
git__free(e);
- return GIT_SUCCESS;
+ return 0;
}
return git_vector_insert(st->vector, e);
@@ -293,7 +294,7 @@ static int determine_status(
enum path_type path_type)
{
struct status_entry *e;
- int error = GIT_SUCCESS;
+ int error = 0;
git_otype tree_entry_type = GIT_OBJ_BAD;
if (tree_entry != NULL)
@@ -317,10 +318,9 @@ static int determine_status(
st->index_position++;
}
- if (in_workdir)
- if ((error = status_entry_update_from_workdir(
- e, full_path->ptr)) < GIT_SUCCESS)
- return error; /* The callee has already set the error message */
+ if (in_workdir &&
+ (error = status_entry_update_from_workdir(e, full_path->ptr)) < 0)
+ return error; /* The callee has already set the error message */
return store_if_changed(st, e);
}
@@ -337,7 +337,7 @@ static int determine_status(
st->tree_position++;
if (in_index)
st->index_position++;
- return GIT_SUCCESS;
+ return 0;
}
static int path_type_from(git_buf *full_path, int is_dir)
@@ -354,7 +354,8 @@ static int path_type_from(git_buf *full_path, int is_dir)
return GIT_STATUS_PATH_FOLDER;
}
-static const char *status_path(const char *first, const char *second, const char *third)
+static const char *status_path(
+ const char *first, const char *second, const char *third)
{
/* At least one of them can not be NULL */
assert(first != NULL || second != NULL || third != NULL);
@@ -399,10 +400,11 @@ static int dirent_cb(void *state, git_buf *a)
path_type = path_type_from(a, st->is_dir);
if (path_type == GIT_STATUS_PATH_IGNORE)
- return GIT_SUCCESS; /* Let's skip the ".git" directory */
+ return 0; /* Let's skip the ".git" directory */
a_name = (path_type != GIT_STATUS_PATH_NULL) ? a->ptr + st->workdir_path_len : NULL;
+ /* Loop over head tree and index up to and including this workdir file */
while (1) {
if (st->tree == NULL)
m = NULL;
@@ -412,7 +414,7 @@ static int dirent_cb(void *state, git_buf *a)
entry = git_index_get(st->index, st->index_position);
if ((m == NULL) && (a == NULL) && (entry == NULL))
- return GIT_SUCCESS;
+ return 0;
if (m != NULL) {
git_buf_truncate(&st->head_tree_relative_path,
@@ -424,7 +426,7 @@ static int dirent_cb(void *state, git_buf *a)
git_path_to_dir(&st->head_tree_relative_path);
if (git_buf_oom(&st->head_tree_relative_path))
- return GIT_ENOMEM;
+ return -1;
m_name = st->head_tree_relative_path.ptr;
} else
@@ -441,11 +443,11 @@ static int dirent_cb(void *state, git_buf *a)
pi = ((cmpmi >= 0) && (cmpai >= 0)) ? i_name : NULL;
if ((error = determine_status(st, pm != NULL, pi != NULL, pa != NULL,
- m, entry, a, status_path(pm, pi, pa), path_type)) < GIT_SUCCESS)
- return git__rethrow(error, "An error occured while determining the status of '%s'", a->ptr);
+ m, entry, a, status_path(pm, pi, pa), path_type)) < 0)
+ return error;
if ((pa != NULL) || (path_type == GIT_STATUS_PATH_FOLDER))
- return GIT_SUCCESS;
+ return 0;
}
}
@@ -469,27 +471,27 @@ int git_status_foreach(
git_index *index = NULL;
git_buf temp_path = GIT_BUF_INIT;
struct status_st dirent_st = {0};
- int error = GIT_SUCCESS;
+ int error = 0;
unsigned int i;
git_tree *tree;
struct status_entry *e;
const char *workdir;
- if ((workdir = git_repository_workdir(repo)) == NULL)
- return git__throw(GIT_ERROR,
- "Cannot retrieve status on a bare repository");
+ assert(repo);
- if ((error = git_repository_index__weakptr(&index, repo)) < GIT_SUCCESS) {
- return git__rethrow(error,
- "Failed to determine statuses. Index can't be opened");
+ if ((workdir = git_repository_workdir(repo)) == NULL ||
+ !git_path_isdir(workdir))
+ {
+ giterr_set(GITERR_OS, "Cannot get status - invalid working directory");
+ return GIT_ENOTFOUND;
}
- if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) {
- error = git__rethrow(error, "Failed to determine statuses");
- goto exit;
- }
+ if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
+ (error = retrieve_head_tree(&tree, repo)) < 0)
+ return error;
- git_vector_init(&entries, DEFAULT_SIZE, status_cmp);
+ if ((error = git_vector_init(&entries, DEFAULT_SIZE, status_cmp)) < 0)
+ goto exit;
dirent_st.repo = repo;
dirent_st.vector = &entries;
@@ -503,42 +505,21 @@ int git_status_foreach(
dirent_st.index_position = 0;
dirent_st.is_dir = 1;
- if (git_path_isdir(workdir) == false) {
- error = git__throw(GIT_EINVALIDPATH,
- "Failed to determine status of file '%s'. "
- "The given path doesn't lead to a folder", workdir);
- goto exit;
- }
-
git_buf_sets(&temp_path, workdir);
- error = git_ignore__for_path(repo, "", dirent_st.ignores);
- if (error < GIT_SUCCESS)
+ if ((error = git_ignore__for_path(repo, "", dirent_st.ignores)) < 0)
goto exit;
- error = alphasorted_futils_direach(
- &temp_path, dirent_cb, &dirent_st);
-
- if (error < GIT_SUCCESS)
- error = git__rethrow(error,
- "Failed to determine statuses. "
- "An error occured while processing the working directory");
+ error = alphasorted_futils_direach(&temp_path, dirent_cb, &dirent_st);
- if ((error == GIT_SUCCESS) &&
- ((error = dirent_cb(&dirent_st, NULL)) < GIT_SUCCESS))
- error = git__rethrow(error,
- "Failed to determine statuses. "
- "An error occured while post-processing the HEAD tree and the index");
+ if (!error)
+ error = dirent_cb(&dirent_st, NULL);
for (i = 0; i < entries.length; ++i) {
e = (struct status_entry *)git_vector_get(&entries, i);
- if (error == GIT_SUCCESS) {
+ if (!error)
error = callback(e->path, e->status_flags, payload);
- if (error < GIT_SUCCESS)
- error = git__rethrow(error,
- "Failed to determine statuses. User callback failed");
- }
git__free(e);
}
@@ -557,222 +538,159 @@ static int recurse_tree_entry(git_tree *tree, struct status_entry *e, const char
char *dir_sep;
const git_tree_entry *tree_entry;
git_tree *subtree;
- int error = GIT_SUCCESS;
+ int error;
dir_sep = strchr(path, '/');
if (!dir_sep) {
- tree_entry = git_tree_entry_byname(tree, path);
- if (tree_entry == NULL)
- return GIT_SUCCESS; /* The leaf doesn't exist in the tree*/
-
- status_entry_update_from_tree_entry(e, tree_entry);
- return GIT_SUCCESS;
+ if ((tree_entry = git_tree_entry_byname(tree, path)) != NULL)
+ /* The leaf exists in the tree*/
+ status_entry_update_from_tree_entry(e, tree_entry);
+ return 0;
}
/* Retrieve subtree name */
*dir_sep = '\0';
- tree_entry = git_tree_entry_byname(tree, path);
- if (tree_entry == NULL)
- return GIT_SUCCESS; /* The subtree doesn't exist in the tree*/
+ if ((tree_entry = git_tree_entry_byname(tree, path)) == NULL)
+ return 0; /* The subtree doesn't exist in the tree*/
*dir_sep = '/';
/* Retreive subtree */
- if ((error = git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid)) < GIT_SUCCESS)
- return git__throw(GIT_EOBJCORRUPTED, "Can't find tree object '%s'", tree_entry->filename);
+ error = git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid);
+ if (!error) {
+ error = recurse_tree_entry(subtree, e, dir_sep+1);
+ git_tree_free(subtree);
+ }
- error = recurse_tree_entry(subtree, e, dir_sep+1);
- git_tree_free(subtree);
return error;
}
-int git_status_file(unsigned int *status_flags, git_repository *repo, const char *path)
+int git_status_file(
+ unsigned int *status_flags, git_repository *repo, const char *path)
{
struct status_entry *e;
git_index *index = NULL;
git_buf temp_path = GIT_BUF_INIT;
- int error = GIT_SUCCESS;
+ int error = 0;
git_tree *tree = NULL;
const char *workdir;
assert(status_flags && repo && path);
- if ((workdir = git_repository_workdir(repo)) == NULL)
- return git__throw(GIT_ERROR,
- "Cannot retrieve status on a bare repository");
+ if ((workdir = git_repository_workdir(repo)) == NULL) {
+ giterr_set(GITERR_OS, "Cannot get file status from bare repo");
+ return GIT_ENOTFOUND;
+ }
- if ((error = git_buf_joinpath(&temp_path, workdir, path)) < GIT_SUCCESS)
- return git__rethrow(error,
- "Failed to determine status of file '%s'", path);
+ if (git_buf_joinpath(&temp_path, workdir, path) < 0)
+ return -1;
- if (git_path_isdir(temp_path.ptr) == true) {
+ if (git_path_isdir(temp_path.ptr)) {
+ giterr_set(GITERR_OS, "Cannot get file status for directory '%s'", temp_path.ptr);
git_buf_free(&temp_path);
- return git__throw(GIT_EINVALIDPATH,
- "Failed to determine status of file '%s'. "
- "Given path leads to a folder, not a file", path);
+ return GIT_ENOTFOUND;
}
e = status_entry_new(NULL, path);
- if (e == NULL) {
- git_buf_free(&temp_path);
- return GIT_ENOMEM;
- }
+ GITERR_CHECK_ALLOC(e);
/* Find file in Workdir */
- if (git_path_exists(temp_path.ptr) == true) {
- if ((error = status_entry_update_from_workdir(e, temp_path.ptr)) < GIT_SUCCESS)
- goto cleanup; /* The callee has already set the error message */
- }
+ if (git_path_exists(temp_path.ptr) == true &&
+ (error = status_entry_update_from_workdir(e, temp_path.ptr)) < 0)
+ goto cleanup;
/* Find file in Index */
- if ((error = git_repository_index__weakptr(&index, repo)) < GIT_SUCCESS) {
- git__rethrow(error,
- "Failed to determine status of file '%s'."
- "Index can't be opened", path);
+ if ((error = git_repository_index__weakptr(&index, repo)) < 0)
goto cleanup;
- }
-
status_entry_update_from_index(e, index);
- if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) {
- git__rethrow(error,
- "Failed to determine status of file '%s'", path);
+ /* Try to find file in HEAD */
+ if ((error = retrieve_head_tree(&tree, repo)) < 0)
goto cleanup;
- }
- /* If the repository is not empty, try and locate the file in HEAD */
if (tree != NULL) {
- if ((error = git_buf_sets(&temp_path, path)) < GIT_SUCCESS) {
- git__rethrow(error,
- "Failed to determine status of file '%s'", path);
- goto cleanup;
- }
-
- error = recurse_tree_entry(tree, e, temp_path.ptr);
- if (error < GIT_SUCCESS) {
- git__rethrow(error,
- "Failed to determine status of file '%s'. "
- "An error occured while processing the tree", path);
+ if ((error = git_buf_sets(&temp_path, path)) < 0 ||
+ (error = recurse_tree_entry(tree, e, temp_path.ptr)) < 0)
goto cleanup;
- }
}
/* Determine status */
- if ((error = status_entry_update_flags(e)) < GIT_SUCCESS) {
- git__throw(error, "Nonexistent file");
- goto cleanup;
- }
+ if ((error = status_entry_update_flags(e)) < 0)
+ giterr_set(GITERR_OS, "Cannot find file '%s' to determine status", path);
- if (status_entry_is_ignorable(e)) {
+ if (!error && status_entry_is_ignorable(e)) {
git_ignores ignores;
- if ((error = git_ignore__for_path(repo, path, &ignores)) == GIT_SUCCESS)
+ if ((error = git_ignore__for_path(repo, path, &ignores)) == 0)
error = status_entry_update_ignore(e, &ignores, path);
git_ignore__free(&ignores);
-
- if (error < GIT_SUCCESS)
- goto cleanup;
}
- *status_flags = e->status_flags;
+ if (!error)
+ *status_flags = e->status_flags;
cleanup:
git_buf_free(&temp_path);
git_tree_free(tree);
git__free(e);
+
return error;
}
/*
* git_path_direach is not supposed to return entries in an ordered manner.
- * alphasorted_futils_direach wraps git_path_direach and invokes the callback
- * function by passing it alphabeticcally sorted paths parameters.
+ * alphasorted_futils_direach wraps git_path_dirload and invokes the
+ * callback function by passing it alphabetically sorted path parameters.
*
*/
-
-static char *alphasorted_dirent_info_new(const git_buf *path)
-{
- char *di = git__malloc(path->size + 2);
- if (!di)
- return di;
-
- git_buf_copy_cstr(di, path->size + 1, path);
-
- if (git_path_isdir(path->ptr) == true) {
- /*
- * Append a forward slash to the name to force folders
- * to be ordered in a similar way than in a tree
- *
- * The file "subdir" should appear before the file "subdir.txt"
- * The folder "subdir" should appear after the file "subdir.txt"
- */
- di[path->size] = '/';
- di[path->size + 1] = '\0';
- }
-
- return di;
-}
-
-static int alphasorted_dirent_cb(void *state, git_buf *full_path)
-{
- char *entry;
- git_vector *entry_names;
-
- entry_names = (git_vector *)state;
- entry = alphasorted_dirent_info_new(full_path);
-
- if (entry == NULL)
- return GIT_ENOMEM;
-
- if (git_vector_insert(entry_names, entry) < GIT_SUCCESS) {
- git__free(entry);
- return GIT_ENOMEM;
- }
-
- return GIT_SUCCESS;
-}
-
static int alphasorted_futils_direach(
git_buf *path,
int (*fn)(void *, git_buf *),
void *arg)
{
+ int error;
char *entry;
git_vector entry_names;
unsigned int idx;
- int error = GIT_SUCCESS;
- git_buf entry_path = GIT_BUF_INIT;
- if (git_vector_init(&entry_names, 16, git__strcmp_cb) < GIT_SUCCESS)
- return GIT_ENOMEM;
+ if (git_vector_init(&entry_names, 16, git__strcmp_cb) < 0)
+ return -1;
- error = git_path_direach(path, alphasorted_dirent_cb, &entry_names);
+ if ((error = git_path_dirload(path->ptr, 0, 1, &entry_names)) < 0)
+ return error;
- git_vector_sort(&entry_names);
+ git_vector_foreach(&entry_names, idx, entry) {
+ size_t entry_len = strlen(entry);
+ if (git_path_isdir(entry)) {
+ /* dirload allocated 1 extra byte so there is space for slash */
+ entry[entry_len++] = '/';
+ entry[entry_len] = '\0';
+ }
+ }
- for (idx = 0; idx < entry_names.length; ++idx) {
- entry = (char *)git_vector_get(&entry_names, idx);
+ git_vector_sort(&entry_names);
- /* We have to walk the entire vector even if there was an error,
- * in order to free up memory, but we stop making callbacks after
- * an error.
+ git_vector_foreach(&entry_names, idx, entry) {
+ /* Walk the entire vector even if there is an error, in order to
+ * free up memory, but stop making callbacks after an error.
*/
- if (error == GIT_SUCCESS)
- error = git_buf_sets(&entry_path, entry);
+ if (!error) {
+ git_buf entry_path = GIT_BUF_INIT;
+ git_buf_attach(&entry_path, entry, 0);
- if (error == GIT_SUCCESS) {
((struct status_st *)arg)->is_dir =
- (entry[entry_path.size - 1] == '/');
+ (entry_path.ptr[entry_path.size - 1] == '/');
+
error = fn(arg, &entry_path);
}
git__free(entry);
}
- git_buf_free(&entry_path);
git_vector_free(&entry_names);
+
return error;
}
@@ -782,11 +700,11 @@ int git_status_should_ignore(git_repository *repo, const char *path, int *ignore
int error;
git_ignores ignores;
- if ((error = git_ignore__for_path(repo, path, &ignores)) == GIT_SUCCESS)
- error = git_ignore__lookup(&ignores, path, ignored);
+ 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/util.c b/src/util.c
index d2309124b..679917e36 100644
--- a/src/util.c
+++ b/src/util.c
@@ -38,11 +38,12 @@ int git__fnmatch(const char *pattern, const char *name, int flags)
ret = p_fnmatch(pattern, name, flags);
switch (ret) {
case 0:
- return GIT_SUCCESS;
+ return 0;
case FNM_NOMATCH:
return GIT_ENOMATCH;
default:
- return git__throw(GIT_EOSERR, "Error trying to match path");
+ giterr_set(GITERR_OS, "Error trying to match path");
+ return -1;
}
}
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index 4de4afaa7..5ff33d14a 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -72,9 +72,9 @@ void test_attr_repo__get_one(void)
attr_check_expected(scan->expected, scan->expected_str, value);
}
- cl_git_pass(git_attr_cache__is_cached(g_repo, ".git/info/attributes"));
- cl_git_pass(git_attr_cache__is_cached(g_repo, ".gitattributes"));
- cl_git_pass(git_attr_cache__is_cached(g_repo, "sub/.gitattributes"));
+ cl_assert(git_attr_cache__is_cached(g_repo, ".git/info/attributes"));
+ cl_assert(git_attr_cache__is_cached(g_repo, ".gitattributes"));
+ cl_assert(git_attr_cache__is_cached(g_repo, "sub/.gitattributes"));
}
void test_attr_repo__get_many(void)
@@ -114,7 +114,7 @@ static int count_attrs(
*((int *)payload) += 1;
- return GIT_SUCCESS;
+ return 0;
}
void test_attr_repo__foreach(void)
diff --git a/tests-clar/core/path.c b/tests-clar/core/path.c
index c1e3ef29c..2654ef72b 100644
--- a/tests-clar/core/path.c
+++ b/tests-clar/core/path.c
@@ -348,7 +348,7 @@ static int check_one_walkup_step(void *ref, git_buf *path)
cl_assert(info->expect[info->expect_idx] != NULL);
cl_assert_strequal(info->expect[info->expect_idx], path->ptr);
info->expect_idx++;
- return GIT_SUCCESS;
+ return 0;
}
void test_core_path__11_walkup(void)
diff --git a/tests-clar/object/tree/diff.c b/tests-clar/object/tree/diff.c
index d481b6f2b..cadba8eaf 100644
--- a/tests-clar/object/tree/diff.c
+++ b/tests-clar/object/tree/diff.c
@@ -24,7 +24,7 @@ static void diff_cmp(const git_tree_diff_data *a, const git_tree_diff_data *b)
static int diff_cb(const git_tree_diff_data *diff, void *data)
{
diff_cmp(diff, data);
- return GIT_SUCCESS;
+ return 0;
}
static void test_diff(git_tree *a, git_tree *b, git_tree_diff_cb cb, void *data)
@@ -126,7 +126,7 @@ static int diff_more_cb(const git_tree_diff_data *diff, void *data)
more_data->expect_idx = (more_data->expect_idx + 1) % ARRAY_SIZE(more_data->expect);
- return GIT_SUCCESS;
+ return 0;
}
void test_object_tree_diff__more(void)
diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c
index 99cb9e8b8..5d940077c 100644
--- a/tests-clar/status/ignore.c
+++ b/tests-clar/status/ignore.c
@@ -47,6 +47,6 @@ void test_status_ignore__0(void)
}
/* confirm that ignore files were cached */
- cl_git_pass(git_attr_cache__is_cached(g_repo, ".git/info/exclude"));
- cl_git_pass(git_attr_cache__is_cached(g_repo, ".gitignore"));
+ cl_assert(git_attr_cache__is_cached(g_repo, ".git/info/exclude"));
+ cl_assert(git_attr_cache__is_cached(g_repo, ".gitignore"));
}
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 132ec1fc1..f80975795 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -27,7 +27,7 @@ cb_status__normal( const char *path, unsigned int status_flags, void *payload)
exit:
counts->entry_count++;
- return GIT_SUCCESS;
+ return 0;
}
static int
@@ -40,7 +40,7 @@ cb_status__count(const char *p, unsigned int s, void *payload)
(*count)++;
- return GIT_SUCCESS;
+ return 0;
}
diff --git a/tests/t18-status.c b/tests/t18-status.c
index 2b90ac6f4..bfd6906c1 100644
--- a/tests/t18-status.c
+++ b/tests/t18-status.c
@@ -432,7 +432,7 @@ BEGIN_TEST(singlestatus4, "can't determine the status for a folder")
must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER));
error = git_status_file(&status_flags, repo, "subdir");
- must_be_true(error == GIT_EINVALIDPATH);
+ must_be_true(error < 0);
git_repository_free(repo);