promote commit graph's open_commit() helper to public API
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
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)
{