Commit c4d7a9c4003019cb8f0ef52f8b6d1913eb567917

Stefan Sperling 2018-06-11T03:13:33

replace inline code with call to open_commit() helper

diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 5fb439c..67c8918 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -263,27 +263,38 @@ add_node(struct got_commit_graph_node **new_node,
 	return err;
 }
 
-const struct got_error *
-got_commit_graph_open(struct got_commit_graph **graph,
-    struct got_object_id *commit_id, struct got_repository *repo)
+static const struct got_error *
+open_commit(struct got_commit_object **commit, struct got_object_id *id,
+    struct got_repository *repo)
 {
-	const struct got_error *err = NULL;
+	const struct got_error *err;
 	struct got_object *obj;
-	struct got_commit_object *commit;
-
-	*graph = NULL;
 
-	err = got_object_open(&obj, repo, commit_id);
+	err = got_object_open(&obj, repo, id);
 	if (err)
 		return err;
 	if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
 		err = got_error(GOT_ERR_OBJ_TYPE);
-		got_object_close(obj);
-		return err;
+		goto done;
 	}
 
-	err = got_object_commit_open(&commit, repo, obj);
+	err = got_object_commit_open(commit, repo, obj);
+done:
 	got_object_close(obj);
+	return err;
+}
+
+
+const struct got_error *
+got_commit_graph_open(struct got_commit_graph **graph,
+    struct got_object_id *commit_id, struct got_repository *repo)
+{
+	const struct got_error *err = NULL;
+	struct got_commit_object *commit;
+
+	*graph = NULL;
+
+	err = open_commit(&commit, commit_id, repo);
 	if (err)
 		return err;
 
@@ -304,27 +315,6 @@ got_commit_graph_open(struct got_commit_graph **graph,
 	return NULL;
 }
 
-static const struct got_error *
-open_commit(struct got_commit_object **commit, struct got_object_id *id,
-    struct got_repository *repo)
-{
-	const struct got_error *err;
-	struct got_object *obj;
-
-	err = got_object_open(&obj, repo, id);
-	if (err)
-		return err;
-	if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
-		err = got_error(GOT_ERR_OBJ_TYPE);
-		goto done;
-	}
-
-	err = got_object_commit_open(commit, repo, obj);
-done:
-	got_object_close(obj);
-	return err;
-}
-
 struct got_commit_graph_branch {
 	struct got_object_id parent_id;
 	struct got_commit_graph_node *node;