Commit be6a1b5ad07f0e2c832ce7de6f07c87fbe1935a5

Stefan Sperling 2018-06-11T03:17:51

promote commit graph's open_commit() helper to public API

diff --git a/include/got_object.h b/include/got_object.h
index a364520..1f6e4e0 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -180,5 +180,10 @@ const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
  */
 const struct got_error *got_object_blob_read_block(size_t *,
     struct got_blob_object *);
+
+const struct got_error *
+got_object_open_as_commit(struct got_commit_object **,
+    struct got_repository *, struct got_object_id *);
+
 const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
     const char *);
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 67c8918..89f1d2c 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -263,28 +263,6 @@ add_node(struct got_commit_graph_node **new_node,
 	return err;
 }
 
-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;
-}
-
-
 const struct got_error *
 got_commit_graph_open(struct got_commit_graph **graph,
     struct got_object_id *commit_id, struct got_repository *repo)
@@ -294,7 +272,7 @@ got_commit_graph_open(struct got_commit_graph **graph,
 
 	*graph = NULL;
 
-	err = open_commit(&commit, commit_id, repo);
+	err = got_object_open_as_commit(&commit, repo, commit_id);
 	if (err)
 		return err;
 
@@ -368,7 +346,7 @@ fetch_commits_from_open_branches(int *ncommits,
 		commit_id = &branches[i].parent_id;
 		child_node = branches[i].node;
 
-		err = open_commit(&commit, commit_id, repo);
+		err = got_object_open_as_commit(&commit, repo, commit_id);
 		if (err)
 			break;
 
diff --git a/lib/object.c b/lib/object.c
index cc3271a..498d4c5 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -441,6 +441,27 @@ got_object_commit_alloc_partial(void)
 }
 
 const struct got_error *
+got_object_open_as_commit(struct got_commit_object **commit,
+    struct got_repository *repo, struct got_object_id *id)
+{
+	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;
+}
+
+const struct got_error *
 got_object_commit_add_parent(struct got_commit_object *commit,
     const char *id_str)
 {