Commit de141d4bb983dad861835e181e7ecd5692a58aba

Vicent Marti 2010-05-28T02:02:02

Improved error handling on auxilirary functions. Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Andreas Ericsson <ae@op5.se>

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;