Improved error handling on auxilirary functions. Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Andreas Ericsson <ae@op5.se>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
diff --git a/src/commit.c b/src/commit.c
index 46c7d0d..ca52813 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -75,27 +75,27 @@ error_cleanup:
int git_commit_parse_existing(git_commit *commit)
{
+ int error = 0;
git_obj commit_obj;
if (commit->parsed)
return 0;
- if (git_odb_read(&commit_obj, commit->object.pool->db, &commit->object.id) < 0)
- return GIT_ENOTFOUND;
+ error = git_odb_read(&commit_obj, commit->object.pool->db, &commit->object.id);
+ if (error < 0)
+ return error;
if (commit_obj.type != GIT_OBJ_COMMIT)
- goto error_cleanup;
-
- if (git_commit__parse_buffer(commit, commit_obj.data, commit_obj.len) < 0)
- goto error_cleanup;
-
- git_obj_close(&commit_obj);
+ {
+ error = GIT_EOBJTYPE;
+ goto cleanup;
+ }
- return 0;
+ error = git_commit__parse_buffer(commit, commit_obj.data, commit_obj.len);
-error_cleanup:
+cleanup:
git_obj_close(&commit_obj);
- return -1;
+ return error;
}
git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id)
@@ -205,7 +205,8 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
if (commit->uninteresting)
parent->uninteresting = 1;
- git_commit_list_push_back(&commit->parents, parent);
+ if (git_commit_list_push_back(&commit->parents, parent))
+ return GIT_ENOMEM;
}
if (git_commit__parse_time(&commit->commit_time, buffer, buffer_end) < 0)
diff --git a/src/revobject.c b/src/revobject.c
index 182f2b3..a9e9df3 100644
--- a/src/revobject.c
+++ b/src/revobject.c
@@ -74,14 +74,14 @@ int git_revpool_table_insert(git_revpool_table *table, git_revpool_object *objec
unsigned int index, hash;
if (table == NULL)
- return -1;
+ return GIT_ERROR;
if (table->count + 1 > table->max_count)
git_revpool_table_resize(table);
node = git__malloc(sizeof(git_revpool_node));
if (node == NULL)
- return -1;
+ return GIT_ENOMEM;
hash = git_revpool_table__hash(&object->id);
index = (hash & table->size_mask);
diff --git a/src/revwalk.c b/src/revwalk.c
index 186a08f..2a6d97c 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -71,8 +71,9 @@ int gitrp_push(git_revpool *pool, git_commit *commit)
return GIT_ERROR;
if (!commit->parsed) {
- if (git_commit_parse_existing(commit) < 0)
- return GIT_EOBJCORRUPTED;
+ int error = git_commit_parse_existing(commit);
+ if (error < 0)
+ return error;
}
// Sanity check: make sure that if the commit
@@ -105,8 +106,9 @@ int gitrp__enroot(git_revpool *pool, git_commit *commit)
return 0;
if (commit->parsed == 0) {
- if (git_commit_parse_existing(commit))
- return GIT_EOBJCORRUPTED;
+ error = git_commit_parse_existing(commit);
+ if (error < 0)
+ return error;
}
commit->seen = 1;