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.
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
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;