Added git_commit_create_oid
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
diff --git a/include/git2/commit.h b/include/git2/commit.h
index 764053e..e7ef518 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -287,6 +287,26 @@ GIT_EXTERN(int) git_commit_create_v(
int parent_count,
...);
+/**
+ * Create a new commit in the repository, as with `git_commit_create`,
+ * using `git_oid` instances as parameters instead of `git_object`.
+ *
+ * See documentation for `git_commit_create` for information about the
+ * parameters, as the meaning is identical excepting that `tree` and
+ * `parents` now take `git_oid`.
+ */
+GIT_EXTERN(int) git_commit_create_oid(
+ git_oid *oid,
+ git_repository *repo,
+ const char *update_ref,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message_encoding,
+ const char *message,
+ const git_oid *tree,
+ int parent_count,
+ const git_oid *parents[]);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/src/commit.c b/src/commit.c
index c7b83ed..e6bfd95 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -76,7 +76,7 @@ int git_commit_create_v(
return res;
}
-int git_commit_create(
+int git_commit_create_oid(
git_oid *oid,
git_repository *repo,
const char *update_ref,
@@ -84,22 +84,18 @@ int git_commit_create(
const git_signature *committer,
const char *message_encoding,
const char *message,
- const git_tree *tree,
+ const git_oid *tree,
int parent_count,
- const git_commit *parents[])
+ const git_oid *parents[])
{
git_buf commit = GIT_BUF_INIT;
int i;
git_odb *odb;
- assert(git_object_owner((const git_object *)tree) == repo);
-
- git_oid__writebuf(&commit, "tree ", git_object_id((const git_object *)tree));
+ git_oid__writebuf(&commit, "tree ", tree);
- for (i = 0; i < parent_count; ++i) {
- assert(git_object_owner((const git_object *)parents[i]) == repo);
- git_oid__writebuf(&commit, "parent ", git_object_id((const git_object *)parents[i]));
- }
+ for (i = 0; i < parent_count; ++i)
+ git_oid__writebuf(&commit, "parent ", parents[i]);
git_signature__writebuf(&commit, "author ", author);
git_signature__writebuf(&commit, "committer ", committer);
@@ -131,6 +127,40 @@ on_error:
return -1;
}
+int git_commit_create(
+ git_oid *oid,
+ git_repository *repo,
+ const char *update_ref,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message_encoding,
+ const char *message,
+ const git_tree *tree,
+ int parent_count,
+ const git_commit *parents[])
+{
+ int retval, i;
+ const git_oid **parent_oids;
+
+ assert(git_object_owner((const git_object *)tree) == repo);
+
+ parent_oids = git__malloc(parent_count * sizeof(git_oid *));
+ GITERR_CHECK_ALLOC(parent_oids);
+
+ for (i = 0; i < parent_count; ++i) {
+ assert(git_object_owner((const git_object *)parents[i]) == repo);
+ parent_oids[i] = git_object_id((const git_object *)parents[i]);
+ }
+
+ retval = git_commit_create_oid(oid, repo, update_ref, author, committer,
+ message_encoding, message,
+ git_object_id((const git_object *)tree),
+ parent_count, parent_oids);
+
+ git__free((void *)parent_oids);
+ return retval;
+}
+
int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
{
const char *buffer = data;