Commit d5e44d84983ba199a62ec67f823312584339fae3

Russell Belfer 2012-11-29T17:02:27

Fix function name and add real error check `revwalk.h:commit_lookup()` -> `git_revwalk__commit_lookup()` and make `git_commit_list_parse()` do real error checking that the item in the list is an actual commit object. Also fixed an apparent typo in a test name.

diff --git a/src/commit_list.c b/src/commit_list.c
index c1a7b22..734e105 100644
--- a/src/commit_list.c
+++ b/src/commit_list.c
@@ -127,7 +127,7 @@ static int commit_quick_parse(git_revwalk *walk, git_commit_list_node *commit, g
 		if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < 0)
 			return -1;
 
-		commit->parents[i] = commit_lookup(walk, &oid);
+		commit->parents[i] = git_revwalk__commit_lookup(walk, &oid);
 		if (commit->parents[i] == NULL)
 			return -1;
 
@@ -181,9 +181,13 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
 
 	if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
 		return error;
-	assert(obj->raw.type == GIT_OBJ_COMMIT);
 
-	error = commit_quick_parse(walk, commit, &obj->raw);
+	if (obj->raw.type == GIT_OBJ_COMMIT) {
+		giterr_set(GITERR_INVALID, "Object is no commit object");
+		error = -1;
+	} else
+		error = commit_quick_parse(walk, commit, &obj->raw);
+
 	git_odb_object_free(obj);
 	return error;
 }
diff --git a/src/graph.c b/src/graph.c
index ff0a846..28026d4 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -58,7 +58,7 @@ int git_graph_ahead_behind(size_t *ahead, size_t *behind, git_repository *repo,
 	if (git_revwalk_new(&walk, repo) < 0)
 		return -1;
 
-	commit2 = commit_lookup(walk, two);
+	commit2 = git_revwalk__commit_lookup(walk, two);
 	if (commit2 == NULL)
 		goto on_error;
 
@@ -68,7 +68,7 @@ int git_graph_ahead_behind(size_t *ahead, size_t *behind, git_repository *repo,
 	list.length = 1;
 	list.contents = contents;
 
-	commit1 = commit_lookup(walk, one);
+	commit1 = git_revwalk__commit_lookup(walk, one);
 	if (commit1 == NULL)
 		goto on_error;
 
diff --git a/src/merge.c b/src/merge.c
index 323b7b8..1386d09 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -71,14 +71,14 @@ int git_merge_base_many(git_oid *out, git_repository *repo, const git_oid input_
 		goto cleanup;
 
 	for (i = 1; i < length; i++) {
-		commit = commit_lookup(walk, &input_array[i]);
+		commit = git_revwalk__commit_lookup(walk, &input_array[i]);
 		if (commit == NULL)
 			goto cleanup;
 
 		git_vector_insert(&list, commit);
 	}
 
-	commit = commit_lookup(walk, &input_array[0]);
+	commit = git_revwalk__commit_lookup(walk, &input_array[0]);
 	if (commit == NULL)
 		goto cleanup;
 
@@ -112,7 +112,7 @@ int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const
 	if (git_revwalk_new(&walk, repo) < 0)
 		return -1;
 
-	commit = commit_lookup(walk, two);
+	commit = git_revwalk__commit_lookup(walk, two);
 	if (commit == NULL)
 		goto on_error;
 
@@ -122,7 +122,7 @@ int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const
 	list.length = 1;
 	list.contents = contents;
 
-	commit = commit_lookup(walk, one);
+	commit = git_revwalk__commit_lookup(walk, one);
 	if (commit == NULL)
 		goto on_error;
 
diff --git a/src/revwalk.c b/src/revwalk.c
index bdbbdbd..cad2f09 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -15,7 +15,8 @@
 
 #include <regex.h>
 
-git_commit_list_node *commit_lookup(git_revwalk *walk, const git_oid *oid)
+git_commit_list_node *git_revwalk__commit_lookup(
+	git_revwalk *walk, const git_oid *oid)
 {
 	git_commit_list_node *commit;
 	khiter_t pos;
@@ -101,7 +102,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
 		return -1;
 	}
 
-	commit = commit_lookup(walk, oid);
+	commit = git_revwalk__commit_lookup(walk, oid);
 	if (commit == NULL)
 		return -1; /* error already reported by failed lookup */
 
diff --git a/src/revwalk.h b/src/revwalk.h
index 2d482cf..6146eaf 100644
--- a/src/revwalk.h
+++ b/src/revwalk.h
@@ -39,6 +39,6 @@ struct git_revwalk {
 	git_vector twos;
 };
 
-git_commit_list_node *commit_lookup(git_revwalk *walk, const git_oid *oid);
+git_commit_list_node *git_revwalk__commit_lookup(git_revwalk *walk, const git_oid *oid);
 
 #endif
diff --git a/tests-clar/revwalk/mergebase.c b/tests-clar/revwalk/mergebase.c
index 2cd1860..0eb6a9b 100644
--- a/tests-clar/revwalk/mergebase.c
+++ b/tests-clar/revwalk/mergebase.c
@@ -83,7 +83,7 @@ void test_revwalk_mergebase__merged_branch(void)
 	cl_assert(behind == 0);
 }
 
-void test_revwalk_meregebase__two_way_merge(void)
+void test_revwalk_mergebase__two_way_merge(void)
 {
 	git_oid one, two;
 	size_t ahead, behind;