Commit 6f02c3ba by nulltoken

Small source code readability improvements.

Replaced magic number "0" with GIT_SUCCESS constant wherever it made sense.
parent d3e2dd5e
...@@ -40,7 +40,7 @@ const char *git_blob_rawcontent(git_blob *blob) ...@@ -40,7 +40,7 @@ const char *git_blob_rawcontent(git_blob *blob)
if (blob->object.in_memory) if (blob->object.in_memory)
return NULL; return NULL;
if (!blob->object.source.open && git_object__source_open((git_object *)blob) < 0) if (!blob->object.source.open && git_object__source_open((git_object *)blob) < GIT_SUCCESS)
return NULL; return NULL;
return blob->object.source.raw.data; return blob->object.source.raw.data;
...@@ -119,13 +119,13 @@ int git_blob_writefile(git_oid *written_id, git_repository *repo, const char *pa ...@@ -119,13 +119,13 @@ int git_blob_writefile(git_oid *written_id, git_repository *repo, const char *pa
if (gitfo_exists(path) < 0) if (gitfo_exists(path) < 0)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
if ((error = git_blob_new(&blob, repo)) < 0) if ((error = git_blob_new(&blob, repo)) < GIT_SUCCESS)
return error; return error;
if ((error = git_blob_set_rawcontent_fromfile(blob, path)) < 0) if ((error = git_blob_set_rawcontent_fromfile(blob, path)) < GIT_SUCCESS)
return error; return error;
if ((error = git_object_write((git_object *)blob)) < 0) if ((error = git_object_write((git_object *)blob)) < GIT_SUCCESS)
return error; return error;
git_oid_cpy(written_id, git_object_id((git_object *)blob)); git_oid_cpy(written_id, git_object_id((git_object *)blob));
......
...@@ -114,23 +114,23 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int ...@@ -114,23 +114,23 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
clear_parents(commit); clear_parents(commit);
if ((error = git__parse_oid(&oid, &buffer, buffer_end, "tree ")) < 0) if ((error = git__parse_oid(&oid, &buffer, buffer_end, "tree ")) < GIT_SUCCESS)
return error; return error;
if ((error = git_repository_lookup((git_object **)&commit->tree, commit->object.repo, &oid, GIT_OBJ_TREE)) < 0) if ((error = git_repository_lookup((git_object **)&commit->tree, commit->object.repo, &oid, GIT_OBJ_TREE)) < GIT_SUCCESS)
return error; return error;
/* /*
* TODO: commit grafts! * TODO: commit grafts!
*/ */
while (git__parse_oid(&oid, &buffer, buffer_end, "parent ") == 0) { while (git__parse_oid(&oid, &buffer, buffer_end, "parent ") == GIT_SUCCESS) {
git_commit *parent; git_commit *parent;
if ((error = git_repository_lookup((git_object **)&parent, commit->object.repo, &oid, GIT_OBJ_COMMIT)) < 0) if ((error = git_repository_lookup((git_object **)&parent, commit->object.repo, &oid, GIT_OBJ_COMMIT)) < GIT_SUCCESS)
return error; return error;
if (git_vector_insert(&commit->parents, parent) < 0) if (git_vector_insert(&commit->parents, parent) < GIT_SUCCESS)
return GIT_ENOMEM; return GIT_ENOMEM;
} }
...@@ -140,7 +140,7 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int ...@@ -140,7 +140,7 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
git_person__free(commit->author); git_person__free(commit->author);
commit->author = git__malloc(sizeof(git_person)); commit->author = git__malloc(sizeof(git_person));
if ((error = git_person__parse(commit->author, &buffer, buffer_end, "author ")) < 0) if ((error = git_person__parse(commit->author, &buffer, buffer_end, "author ")) < GIT_SUCCESS)
return error; return error;
} else { } else {
...@@ -155,7 +155,7 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int ...@@ -155,7 +155,7 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
git_person__free(commit->committer); git_person__free(commit->committer);
commit->committer = git__malloc(sizeof(git_person)); commit->committer = git__malloc(sizeof(git_person));
if ((error = git_person__parse(commit->committer, &buffer, buffer_end, "committer ")) < 0) if ((error = git_person__parse(commit->committer, &buffer, buffer_end, "committer ")) < GIT_SUCCESS)
return error; return error;
commit->commit_time = commit->committer->time; commit->commit_time = commit->committer->time;
...@@ -199,9 +199,9 @@ int git_commit__parse_full(git_commit *commit) ...@@ -199,9 +199,9 @@ int git_commit__parse_full(git_commit *commit)
int error; int error;
if (commit->full_parse) if (commit->full_parse)
return 0; return GIT_SUCCESS;
if ((error = git_object__source_open((git_object *)commit)) < 0) if ((error = git_object__source_open((git_object *)commit)) < GIT_SUCCESS)
return error; return error;
error = commit_parse_buffer(commit, error = commit_parse_buffer(commit,
......
...@@ -49,7 +49,7 @@ int git_filelock_init(git_filelock *lock, const char *path) ...@@ -49,7 +49,7 @@ int git_filelock_init(git_filelock *lock, const char *path)
return GIT_ERROR; return GIT_ERROR;
memcpy(lock->path, path, lock->path_length); memcpy(lock->path, path, lock->path_length);
return 0; return GIT_SUCCESS;
} }
int git_filelock_lock(git_filelock *lock, int append) int git_filelock_lock(git_filelock *lock, int append)
...@@ -85,7 +85,7 @@ int git_filelock_lock(git_filelock *lock, int append) ...@@ -85,7 +85,7 @@ int git_filelock_lock(git_filelock *lock, int append)
gitfo_close(source); gitfo_close(source);
} }
return 0; return GIT_SUCCESS;
} }
void git_filelock_unlock(git_filelock *lock) void git_filelock_unlock(git_filelock *lock)
...@@ -116,7 +116,7 @@ int git_filelock_commit(git_filelock *lock) ...@@ -116,7 +116,7 @@ int git_filelock_commit(git_filelock *lock)
error = gitfo_move_file(path_lock, lock->path); error = gitfo_move_file(path_lock, lock->path);
if (error < 0) if (error < GIT_SUCCESS)
gitfo_unlink(path_lock); gitfo_unlink(path_lock);
lock->is_locked = 0; lock->is_locked = 0;
......
...@@ -151,7 +151,7 @@ int gitfo_move_file(char *from, char *to) ...@@ -151,7 +151,7 @@ int gitfo_move_file(char *from, char *to)
int gitfo_map_ro(git_map *out, git_file fd, off_t begin, size_t len) int gitfo_map_ro(git_map *out, git_file fd, off_t begin, size_t len)
{ {
if (git__mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin) < 0) if (git__mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin) < GIT_SUCCESS)
return git_os_error(); return git_os_error();
return GIT_SUCCESS; return GIT_SUCCESS;
} }
...@@ -240,7 +240,7 @@ int gitfo_close_cached(gitfo_cache *ioc) ...@@ -240,7 +240,7 @@ int gitfo_close_cached(gitfo_cache *ioc)
{ {
git_file fd; git_file fd;
if (gitfo_flush_cached(ioc) < 0) if (gitfo_flush_cached(ioc) < GIT_SUCCESS)
return GIT_ERROR; return GIT_ERROR;
fd = ioc->fd; fd = ioc->fd;
...@@ -292,7 +292,7 @@ int gitfo_dirent( ...@@ -292,7 +292,7 @@ int gitfo_dirent(
strcpy(path + wd_len, de->d_name); strcpy(path + wd_len, de->d_name);
result = fn(arg, path); result = fn(arg, path);
if (result < 0) { if (result < GIT_SUCCESS) {
closedir(dir); closedir(dir);
return result; return result;
} }
......
...@@ -196,14 +196,14 @@ void git_index_free(git_index *index) ...@@ -196,14 +196,14 @@ void git_index_free(git_index *index)
int git_index_read(git_index *index) int git_index_read(git_index *index)
{ {
struct stat indexst; struct stat indexst;
int error = 0; int error = GIT_SUCCESS;
assert(index->index_file_path); assert(index->index_file_path);
if (!index->on_disk || gitfo_exists(index->index_file_path) < 0) { if (!index->on_disk || gitfo_exists(index->index_file_path) < 0) {
git_index_clear(index); git_index_clear(index);
index->on_disk = 0; index->on_disk = 0;
return 0; return GIT_SUCCESS;
} }
if (gitfo_stat(index->index_file_path, &indexst) < 0) if (gitfo_stat(index->index_file_path, &indexst) < 0)
...@@ -216,13 +216,13 @@ int git_index_read(git_index *index) ...@@ -216,13 +216,13 @@ int git_index_read(git_index *index)
gitfo_buf buffer; gitfo_buf buffer;
if (gitfo_read_file(&buffer, index->index_file_path) < 0) if (gitfo_read_file(&buffer, index->index_file_path) < GIT_SUCCESS)
return GIT_EOSERR; return GIT_EOSERR;
git_index_clear(index); git_index_clear(index);
error = git_index__parse(index, buffer.data, buffer.len); error = git_index__parse(index, buffer.data, buffer.len);
if (error == 0) if (error == GIT_SUCCESS)
index->last_modified = indexst.st_mtime; index->last_modified = indexst.st_mtime;
gitfo_free_buf(&buffer); gitfo_free_buf(&buffer);
...@@ -239,18 +239,18 @@ int git_index_write(git_index *index) ...@@ -239,18 +239,18 @@ int git_index_write(git_index *index)
if (!index->sorted) if (!index->sorted)
git_index__sort(index); git_index__sort(index);
if (git_filelock_init(&file, index->index_file_path) < 0) if (git_filelock_init(&file, index->index_file_path) < GIT_SUCCESS)
return GIT_EFLOCKFAIL; return GIT_EFLOCKFAIL;
if (git_filelock_lock(&file, 0) < 0) if (git_filelock_lock(&file, 0) < GIT_SUCCESS)
return GIT_EFLOCKFAIL; return GIT_EFLOCKFAIL;
if (git_index__write(index, &file) < 0) { if (git_index__write(index, &file) < GIT_SUCCESS) {
git_filelock_unlock(&file); git_filelock_unlock(&file);
return GIT_EOSERR; return GIT_EOSERR;
} }
if (git_filelock_commit(&file) < 0) if (git_filelock_commit(&file) < GIT_SUCCESS)
return GIT_EFLOCKFAIL; return GIT_EFLOCKFAIL;
if (gitfo_stat(index->index_file_path, &indexst) == 0) { if (gitfo_stat(index->index_file_path, &indexst) == 0) {
...@@ -258,7 +258,7 @@ int git_index_write(git_index *index) ...@@ -258,7 +258,7 @@ int git_index_write(git_index *index)
index->on_disk = 1; index->on_disk = 1;
} }
return 0; return GIT_SUCCESS;
} }
unsigned int git_index_entrycount(git_index *index) unsigned int git_index_entrycount(git_index *index)
...@@ -310,7 +310,7 @@ int git_index_add(git_index *index, const char *rel_path, int stage) ...@@ -310,7 +310,7 @@ int git_index_add(git_index *index, const char *rel_path, int stage)
entry.file_size = st.st_size; entry.file_size = st.st_size;
/* write the blob to disk and get the oid */ /* write the blob to disk and get the oid */
if ((error = git_blob_writefile(&entry.oid, index->repository, full_path)) < 0) if ((error = git_blob_writefile(&entry.oid, index->repository, full_path)) < GIT_SUCCESS)
return error; return error;
entry.flags |= (stage << GIT_IDXENTRY_STAGESHIFT); entry.flags |= (stage << GIT_IDXENTRY_STAGESHIFT);
...@@ -366,7 +366,7 @@ int git_index_insert(git_index *index, const git_index_entry *source_entry) ...@@ -366,7 +366,7 @@ int git_index_insert(git_index *index, const git_index_entry *source_entry)
/* if no entry exists, add the entry at the end; /* if no entry exists, add the entry at the end;
* the index is no longer sorted */ * the index is no longer sorted */
if (position == GIT_ENOTFOUND) { if (position == GIT_ENOTFOUND) {
if (git_vector_insert(&index->entries, entry) < 0) if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS)
return GIT_ENOMEM; return GIT_ENOMEM;
index->sorted = 0; index->sorted = 0;
...@@ -480,7 +480,7 @@ static int read_tree(git_index *index, const char *buffer, size_t buffer_size) ...@@ -480,7 +480,7 @@ static int read_tree(git_index *index, const char *buffer, size_t buffer_size)
const char *buffer_end = buffer + buffer_size; const char *buffer_end = buffer + buffer_size;
index->tree = read_tree_internal(&buffer, buffer_end, NULL); index->tree = read_tree_internal(&buffer, buffer_end, NULL);
return (index->tree != NULL && buffer == buffer_end) ? 0 : GIT_EOBJCORRUPTED; return (index->tree != NULL && buffer == buffer_end) ? GIT_SUCCESS : GIT_EOBJCORRUPTED;
} }
static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffer_size) static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffer_size)
...@@ -561,7 +561,7 @@ static int read_header(struct index_header *dest, const void *buffer) ...@@ -561,7 +561,7 @@ static int read_header(struct index_header *dest, const void *buffer)
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
dest->entry_count = ntohl(source->entry_count); dest->entry_count = ntohl(source->entry_count);
return 0; return GIT_SUCCESS;
} }
static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size) static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size)
...@@ -585,7 +585,7 @@ static size_t read_extension(git_index *index, const char *buffer, size_t buffer ...@@ -585,7 +585,7 @@ static size_t read_extension(git_index *index, const char *buffer, size_t buffer
/* tree cache */ /* tree cache */
if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) { if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) {
if (read_tree(index, buffer + 8, dest.extension_size) < 0) if (read_tree(index, buffer + 8, dest.extension_size) < GIT_SUCCESS)
return 0; return 0;
} }
} else { } else {
...@@ -618,7 +618,7 @@ int git_index__parse(git_index *index, const char *buffer, size_t buffer_size) ...@@ -618,7 +618,7 @@ int git_index__parse(git_index *index, const char *buffer, size_t buffer_size)
git_hash_buf(&checksum_calculated, (const void *)buffer, buffer_size - INDEX_FOOTER_SIZE); git_hash_buf(&checksum_calculated, (const void *)buffer, buffer_size - INDEX_FOOTER_SIZE);
/* Parse header */ /* Parse header */
if (read_header(&header, buffer) < 0) if (read_header(&header, buffer) < GIT_SUCCESS)
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
seek_forward(INDEX_HEADER_SIZE); seek_forward(INDEX_HEADER_SIZE);
...@@ -640,7 +640,7 @@ int git_index__parse(git_index *index, const char *buffer, size_t buffer_size) ...@@ -640,7 +640,7 @@ int git_index__parse(git_index *index, const char *buffer, size_t buffer_size)
if (entry_size == 0) if (entry_size == 0)
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
if (git_vector_insert(&index->entries, entry) < 0) if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS)
return GIT_ENOMEM; return GIT_ENOMEM;
seek_forward(entry_size); seek_forward(entry_size);
...@@ -673,14 +673,14 @@ int git_index__parse(git_index *index, const char *buffer, size_t buffer_size) ...@@ -673,14 +673,14 @@ int git_index__parse(git_index *index, const char *buffer, size_t buffer_size)
#undef seek_forward #undef seek_forward
return 0; return GIT_SUCCESS;
} }
int git_index__write(git_index *index, git_filelock *file) int git_index__write(git_index *index, git_filelock *file)
{ {
static const char NULL_BYTES[] = {0, 0, 0, 0, 0, 0, 0, 0}; static const char NULL_BYTES[] = {0, 0, 0, 0, 0, 0, 0, 0};
int error = 0; int error = GIT_SUCCESS;
unsigned int i; unsigned int i;
git_hash_ctx *digest; git_hash_ctx *digest;
......
...@@ -1178,7 +1178,7 @@ static int open_pack(git_pack *p) ...@@ -1178,7 +1178,7 @@ static int open_pack(git_pack *p)
goto error_cleanup; goto error_cleanup;
if (!git__is_sizet(p->pack_size) || if (!git__is_sizet(p->pack_size) ||
gitfo_map_ro(&p->pack_map, p->pack_fd, 0, (size_t)p->pack_size) < 0) gitfo_map_ro(&p->pack_map, p->pack_fd, 0, (size_t)p->pack_size) < GIT_SUCCESS)
goto error_cleanup; goto error_cleanup;
pack_decidx(p); pack_decidx(p);
...@@ -1261,25 +1261,25 @@ static int scan_one_pack(void *state, char *name) ...@@ -1261,25 +1261,25 @@ static int scan_one_pack(void *state, char *name)
if (git__prefixcmp(s + 1, "pack-") if (git__prefixcmp(s + 1, "pack-")
|| git__suffixcmp(s, ".pack") || git__suffixcmp(s, ".pack")
|| strlen(s + 1) != GIT_PACK_NAME_MAX + 4) || strlen(s + 1) != GIT_PACK_NAME_MAX + 4)
return 0; return GIT_SUCCESS;
d = strrchr(s + 1, '.'); d = strrchr(s + 1, '.');
strcpy(d + 1, "idx"); /* "pack-abc.pack" -> "pack-abc.idx" */ strcpy(d + 1, "idx"); /* "pack-abc.pack" -> "pack-abc.idx" */
if (gitfo_exists(name)) if (gitfo_exists(name))
return 0; return GIT_SUCCESS;
if ((r = git__malloc(sizeof(*r))) == NULL) if ((r = git__malloc(sizeof(*r))) == NULL)
return GIT_ERROR; return GIT_ERROR; /* GIT_ENOMEM? */
*d = '\0'; /* "pack-abc.pack" -_> "pack-abc" */ *d = '\0'; /* "pack-abc.pack" -_> "pack-abc" */
if ((r->pack = alloc_pack(s + 1)) == NULL) { if ((r->pack = alloc_pack(s + 1)) == NULL) {
free(r); free(r);
return GIT_ERROR; return GIT_ERROR; /* GIT_ENOMEM? */
} }
r->next = *ret; r->next = *ret;
*ret = r; *ret = r;
return 0; return GIT_SUCCESS;
} }
static git_packlist *scan_packs(git_odb *db) static git_packlist *scan_packs(git_odb *db)
...@@ -1559,7 +1559,7 @@ static int open_alternates(git_odb *db) ...@@ -1559,7 +1559,7 @@ static int open_alternates(git_odb *db)
db->alternates[n] = NULL; db->alternates[n] = NULL;
db->n_alternates = n; db->n_alternates = n;
gitlck_unlock(&db->lock); gitlck_unlock(&db->lock);
return 0; return GIT_SUCCESS;
} }
...@@ -1614,8 +1614,8 @@ static int read_header_packed(git_rawobj *out, const obj_location *loc) ...@@ -1614,8 +1614,8 @@ static int read_header_packed(git_rawobj *out, const obj_location *loc)
if (pack_openidx(pack)) if (pack_openidx(pack))
return GIT_EPACKCORRUPTED; return GIT_EPACKCORRUPTED;
if (pack->idx_get(&e, pack, loc->pack.n) < 0 || if (pack->idx_get(&e, pack, loc->pack.n) < GIT_SUCCESS ||
open_pack(pack) < 0) { open_pack(pack) < GIT_SUCCESS) {
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
goto cleanup; goto cleanup;
} }
...@@ -1662,7 +1662,7 @@ static int read_loose(git_rawobj *out, git_odb *db, const obj_location *loc) ...@@ -1662,7 +1662,7 @@ static int read_loose(git_rawobj *out, git_odb *db, const obj_location *loc)
out->len = 0; out->len = 0;
out->type = GIT_OBJ_BAD; out->type = GIT_OBJ_BAD;
if (gitfo_read_file(&obj, loc->loose_path) < 0) if (gitfo_read_file(&obj, loc->loose_path) < GIT_SUCCESS)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
error = inflate_disk_obj(out, &obj); error = inflate_disk_obj(out, &obj);
...@@ -1725,10 +1725,10 @@ static int write_obj(gitfo_buf *buf, git_oid *id, git_odb *db) ...@@ -1725,10 +1725,10 @@ static int write_obj(gitfo_buf *buf, git_oid *id, git_odb *db)
if (object_file_name(file, sizeof(file), db->objects_dir, id)) if (object_file_name(file, sizeof(file), db->objects_dir, id))
return GIT_EOSERR; return GIT_EOSERR;
if (make_temp_file(&fd, temp, sizeof(temp), file) < 0) if (make_temp_file(&fd, temp, sizeof(temp), file) < GIT_SUCCESS)
return GIT_EOSERR; return GIT_EOSERR;
if (gitfo_write(fd, buf->data, buf->len) < 0) { if (gitfo_write(fd, buf->data, buf->len) < GIT_SUCCESS) {
gitfo_close(fd); gitfo_close(fd);
gitfo_unlink(temp); gitfo_unlink(temp);
return GIT_EOSERR; return GIT_EOSERR;
...@@ -1739,7 +1739,7 @@ static int write_obj(gitfo_buf *buf, git_oid *id, git_odb *db) ...@@ -1739,7 +1739,7 @@ static int write_obj(gitfo_buf *buf, git_oid *id, git_odb *db)
gitfo_close(fd); gitfo_close(fd);
gitfo_chmod(temp, 0444); gitfo_chmod(temp, 0444);
if (gitfo_move_file(temp, file) < 0) { if (gitfo_move_file(temp, file) < GIT_SUCCESS) {
gitfo_unlink(temp); gitfo_unlink(temp);
return GIT_EOSERR; return GIT_EOSERR;
} }
...@@ -1839,7 +1839,7 @@ int git_odb_exists(git_odb *db, const git_oid *id) ...@@ -1839,7 +1839,7 @@ int git_odb_exists(git_odb *db, const git_oid *id)
int git_odb_read_header(git_rawobj *out, git_odb *db, const git_oid *id) int git_odb_read_header(git_rawobj *out, git_odb *db, const git_oid *id)
{ {
obj_location loc; obj_location loc;
int found, error = 0; int found, error = GIT_SUCCESS;
assert(out && db); assert(out && db);
...@@ -1868,7 +1868,7 @@ int git_odb_read( ...@@ -1868,7 +1868,7 @@ int git_odb_read(
const git_oid *id) const git_oid *id)
{ {
obj_location loc; obj_location loc;
int found, error = 0; int found, error = GIT_SUCCESS;
assert(out && db); assert(out && db);
...@@ -1900,16 +1900,16 @@ int git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj) ...@@ -1900,16 +1900,16 @@ int git_odb_write(git_oid *id, git_odb *db, git_rawobj *obj)
assert(id && db && obj); assert(id && db && obj);
if ((error = hash_obj(id, hdr, sizeof(hdr), &hdrlen, obj)) < 0) if ((error = hash_obj(id, hdr, sizeof(hdr), &hdrlen, obj)) < GIT_SUCCESS)
return error; return error;
if (git_odb_exists(db, id)) if (git_odb_exists(db, id))
return GIT_SUCCESS; return GIT_SUCCESS;
if ((error = deflate_obj(&buf, hdr, hdrlen, obj, db->object_zlib_level)) < 0) if ((error = deflate_obj(&buf, hdr, hdrlen, obj, db->object_zlib_level)) < GIT_SUCCESS)
return error; return error;
if ((error = write_obj(&buf, id, db)) < 0) { if ((error = write_obj(&buf, id, db)) < GIT_SUCCESS) {
gitfo_free_buf(&buf); gitfo_free_buf(&buf);
return error; return error;
} }
......
...@@ -134,12 +134,12 @@ int git__parse_oid(git_oid *oid, char **buffer_out, ...@@ -134,12 +134,12 @@ int git__parse_oid(git_oid *oid, char **buffer_out,
if (buffer[header_len + sha_len] != '\n') if (buffer[header_len + sha_len] != '\n')
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
if (git_oid_mkstr(oid, buffer + header_len) < 0) if (git_oid_mkstr(oid, buffer + header_len) < GIT_SUCCESS)
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
*buffer_out = buffer + (header_len + sha_len + 1); *buffer_out = buffer + (header_len + sha_len + 1);
return 0; return GIT_SUCCESS;
} }
int git__write_oid(git_odb_source *src, const char *header, const git_oid *oid) int git__write_oid(git_odb_source *src, const char *header, const git_oid *oid)
......
...@@ -129,7 +129,7 @@ int git_person__parse(git_person *person, char **buffer_out, ...@@ -129,7 +129,7 @@ int git_person__parse(git_person *person, char **buffer_out,
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
*buffer_out = (line_end + 1); *buffer_out = (line_end + 1);
return 0; return GIT_SUCCESS;
} }
int git_person__write(git_odb_source *src, const char *header, const git_person *person) int git_person__write(git_odb_source *src, const char *header, const git_person *person)
......
...@@ -84,7 +84,7 @@ static int assign_repository_folders(git_repository *repo, ...@@ -84,7 +84,7 @@ static int assign_repository_folders(git_repository *repo,
assert(repo); assert(repo);
if (git_dir == NULL || gitfo_isdir(git_dir) < 0) if (git_dir == NULL || gitfo_isdir(git_dir) < GIT_SUCCESS)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
...@@ -107,7 +107,7 @@ static int assign_repository_folders(git_repository *repo, ...@@ -107,7 +107,7 @@ static int assign_repository_folders(git_repository *repo,
else else
strcpy(path_aux, git_object_directory); strcpy(path_aux, git_object_directory);
if (gitfo_isdir(path_aux) < 0) if (gitfo_isdir(path_aux) < GIT_SUCCESS)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
repo->path_odb = git__strdup(path_aux); repo->path_odb = git__strdup(path_aux);
...@@ -139,7 +139,7 @@ static int guess_repository_folders(git_repository *repo, const char *repository ...@@ -139,7 +139,7 @@ static int guess_repository_folders(git_repository *repo, const char *repository
char path_aux[GIT_PATH_MAX], *last_folder; char path_aux[GIT_PATH_MAX], *last_folder;
int path_len; int path_len;
if (gitfo_isdir(repository_path) < 0) if (gitfo_isdir(repository_path) < GIT_SUCCESS)
return GIT_ENOTAREPO; return GIT_ENOTAREPO;
path_len = strlen(repository_path); path_len = strlen(repository_path);
...@@ -156,7 +156,7 @@ static int guess_repository_folders(git_repository *repo, const char *repository ...@@ -156,7 +156,7 @@ static int guess_repository_folders(git_repository *repo, const char *repository
/* objects database */ /* objects database */
strcpy(path_aux + path_len, GIT_OBJECTS_FOLDER); strcpy(path_aux + path_len, GIT_OBJECTS_FOLDER);
if (gitfo_isdir(path_aux) < 0) if (gitfo_isdir(path_aux) < GIT_SUCCESS)
return GIT_ENOTAREPO; return GIT_ENOTAREPO;
repo->path_odb = git__strdup(path_aux); repo->path_odb = git__strdup(path_aux);
...@@ -233,11 +233,11 @@ int git_repository_open2(git_repository **repo_out, ...@@ -233,11 +233,11 @@ int git_repository_open2(git_repository **repo_out,
git_index_file, git_index_file,
git_work_tree); git_work_tree);
if (error < 0) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
error = git_odb_open(&repo->db, repo->path_odb); error = git_odb_open(&repo->db, repo->path_odb);
if (error < 0) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
*repo_out = repo; *repo_out = repo;
...@@ -260,11 +260,11 @@ int git_repository_open(git_repository **repo_out, const char *path) ...@@ -260,11 +260,11 @@ int git_repository_open(git_repository **repo_out, const char *path)
return GIT_ENOMEM; return GIT_ENOMEM;
error = guess_repository_folders(repo, path); error = guess_repository_folders(repo, path);
if (error < 0) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
error = git_odb_open(&repo->db, repo->path_odb); error = git_odb_open(&repo->db, repo->path_odb);
if (error < 0) if (error < GIT_SUCCESS)
goto cleanup; goto cleanup;
*repo_out = repo; *repo_out = repo;
...@@ -302,7 +302,7 @@ void git_repository_free(git_repository *repo) ...@@ -302,7 +302,7 @@ void git_repository_free(git_repository *repo)
git_index *git_repository_index(git_repository *repo) git_index *git_repository_index(git_repository *repo)
{ {
if (repo->index == NULL) { if (repo->index == NULL) {
if (git_index_open_inrepo(&repo->index, repo) < 0) if (git_index_open_inrepo(&repo->index, repo) < GIT_SUCCESS)
return NULL; return NULL;
assert(repo->index); assert(repo->index);
...@@ -344,7 +344,7 @@ int git__source_printf(git_odb_source *source, const char *format, ...) ...@@ -344,7 +344,7 @@ int git__source_printf(git_odb_source *source, const char *format, ...)
len = vsnprintf(source->write_ptr, source->raw.len - source->written_bytes, format, arglist); len = vsnprintf(source->write_ptr, source->raw.len - source->written_bytes, format, arglist);
while (source->written_bytes + len >= source->raw.len) { while (source->written_bytes + len >= source->raw.len) {
if (source_resize(source) < 0) if (source_resize(source) < GIT_SUCCESS)
return GIT_ENOMEM; return GIT_ENOMEM;
did_resize = 1; did_resize = 1;
...@@ -366,7 +366,7 @@ int git__source_write(git_odb_source *source, const void *bytes, size_t len) ...@@ -366,7 +366,7 @@ int git__source_write(git_odb_source *source, const void *bytes, size_t len)
assert(source->open && source->write_ptr); assert(source->open && source->write_ptr);
while (source->written_bytes + len >= source->raw.len) { while (source->written_bytes + len >= source->raw.len) {
if (source_resize(source) < 0) if (source_resize(source) < GIT_SUCCESS)
return GIT_ENOMEM; return GIT_ENOMEM;
} }
...@@ -404,7 +404,7 @@ static int write_back(git_object *object) ...@@ -404,7 +404,7 @@ static int write_back(git_object *object)
object->source.raw.len = object->source.written_bytes; object->source.raw.len = object->source.written_bytes;
if ((error = git_odb_write(&new_id, object->repo->db, &object->source.raw)) < 0) if ((error = git_odb_write(&new_id, object->repo->db, &object->source.raw)) < GIT_SUCCESS)
return error; return error;
if (!object->in_memory) if (!object->in_memory)
...@@ -433,7 +433,7 @@ int git_object__source_open(git_object *object) ...@@ -433,7 +433,7 @@ int git_object__source_open(git_object *object)
git_object__source_close(object); git_object__source_close(object);
error = git_odb_read(&object->source.raw, object->repo->db, &object->id); error = git_odb_read(&object->source.raw, object->repo->db, &object->id);
if (error < 0) if (error < GIT_SUCCESS)
return error; return error;
object->source.open = 1; object->source.open = 1;
...@@ -485,7 +485,7 @@ int git_object_write(git_object *object) ...@@ -485,7 +485,7 @@ int git_object_write(git_object *object)
break; break;
} }
if (error < 0) { if (error < GIT_SUCCESS) {
git_object__source_close(object); git_object__source_close(object);
return error; return error;
} }
...@@ -590,7 +590,7 @@ int git_repository_lookup(git_object **object_out, git_repository *repo, const g ...@@ -590,7 +590,7 @@ int git_repository_lookup(git_object **object_out, git_repository *repo, const g
{ {
git_object *object = NULL; git_object *object = NULL;
git_rawobj obj_file; git_rawobj obj_file;
int error = 0; int error = GIT_SUCCESS;
assert(repo && object_out && id); assert(repo && object_out && id);
...@@ -601,7 +601,7 @@ int git_repository_lookup(git_object **object_out, git_repository *repo, const g ...@@ -601,7 +601,7 @@ int git_repository_lookup(git_object **object_out, git_repository *repo, const g
} }
error = git_odb_read(&obj_file, repo->db, id); error = git_odb_read(&obj_file, repo->db, id);
if (error < 0) if (error < GIT_SUCCESS)
return error; return error;
if (type != GIT_OBJ_ANY && type != obj_file.type) if (type != GIT_OBJ_ANY && type != obj_file.type)
...@@ -644,7 +644,7 @@ int git_repository_lookup(git_object **object_out, git_repository *repo, const g ...@@ -644,7 +644,7 @@ int git_repository_lookup(git_object **object_out, git_repository *repo, const g
break; break;
} }
if (error < 0) { if (error < GIT_SUCCESS) {
git_object_free(object); git_object_free(object);
return error; return error;
} }
......
...@@ -206,7 +206,7 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end) ...@@ -206,7 +206,7 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
memcpy(tag->message, buffer, text_len); memcpy(tag->message, buffer, text_len);
tag->message[text_len] = '\0'; tag->message[text_len] = '\0';
return 0; return GIT_SUCCESS;
} }
int git_tag__writeback(git_tag *tag, git_odb_source *src) int git_tag__writeback(git_tag *tag, git_odb_source *src)
......
...@@ -238,12 +238,12 @@ static int tree_parse_buffer(git_tree *tree, char *buffer, char *buffer_end) ...@@ -238,12 +238,12 @@ static int tree_parse_buffer(git_tree *tree, char *buffer, char *buffer_end)
{ {
static const size_t avg_entry_size = 40; static const size_t avg_entry_size = 40;
unsigned int expected_size; unsigned int expected_size;
int error = 0; int error = GIT_SUCCESS;
expected_size = (tree->object.source.raw.len / avg_entry_size) + 1; expected_size = (tree->object.source.raw.len / avg_entry_size) + 1;
free_tree_entries(tree); free_tree_entries(tree);
if (git_vector_init(&tree->entries, expected_size, entry_sort_cmp, entry_search_cmp) < 0) if (git_vector_init(&tree->entries, expected_size, entry_sort_cmp, entry_search_cmp) < GIT_SUCCESS)
return GIT_ENOMEM; return GIT_ENOMEM;
while (buffer < buffer_end) { while (buffer < buffer_end) {
...@@ -255,7 +255,7 @@ static int tree_parse_buffer(git_tree *tree, char *buffer, char *buffer_end) ...@@ -255,7 +255,7 @@ static int tree_parse_buffer(git_tree *tree, char *buffer, char *buffer_end)
break; break;
} }
if (git_vector_insert(&tree->entries, entry) < 0) if (git_vector_insert(&tree->entries, entry) < GIT_SUCCESS)
return GIT_ENOMEM; return GIT_ENOMEM;
entry->owner = tree; entry->owner = tree;
......
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