Commit 0d0fa7c3 by Russell Belfer

Convert attr, ignore, mwindow, status to new errors

Also cleaned up some previously converted code that still had
little things to polish.
parent 4cfe2ab6
......@@ -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(
......
......@@ -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
......@@ -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.
*/
......
......@@ -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;
......
......@@ -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)
......
......@@ -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)
{
......
......@@ -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)
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
}
......@@ -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;
}
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -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 */
......
......@@ -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;
......
......@@ -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
......
......@@ -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(
......
......@@ -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)
......
......@@ -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;
}
}
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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"));
}
......@@ -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;
}
......
......@@ -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);
......
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