summaryrefslogtreecommitdiff
path: root/include/git2/sys/commit.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-01-17 10:45:11 -0800
committerRussell Belfer <rb@github.com>2014-02-07 16:17:59 -0800
commit80c29fe93e968fd73e861546e1a4cf33b514e3f6 (patch)
treedaeef4d5dab50314ec4f0a2afeaf96c65557d3ed /include/git2/sys/commit.h
parent2d9291943c253e9e1520f87b13abb1e81cffdb29 (diff)
downloadlibgit2-80c29fe93e968fd73e861546e1a4cf33b514e3f6.tar.gz
Add git_commit_amend API
This adds an API to amend an existing commit, basically a shorthand for creating a new commit filling in missing parameters from the values of an existing commit. As part of this, I also added a new "sys" API to create a commit using a callback to get the parents. This allowed me to rewrite all the other commit creation APIs so that temporary allocations are no longer needed.
Diffstat (limited to 'include/git2/sys/commit.h')
-rw-r--r--include/git2/sys/commit.h40
1 files changed, 37 insertions, 3 deletions
diff --git a/include/git2/sys/commit.h b/include/git2/sys/commit.h
index c8ed56b66..627d3ae2e 100644
--- a/include/git2/sys/commit.h
+++ b/include/git2/sys/commit.h
@@ -21,16 +21,18 @@
GIT_BEGIN_DECL
/**
- * Create new commit in the repository from a list of `git_oid` values
+ * Create new commit in the repository from a list of `git_oid` values.
*
* 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`. This is a dangerous API in that nor
* the `tree`, neither the `parents` list of `git_oid`s are checked for
* validity.
+ *
+ * @see git_commit_create
*/
GIT_EXTERN(int) git_commit_create_from_ids(
- git_oid *oid,
+ git_oid *id,
git_repository *repo,
const char *update_ref,
const git_signature *author,
@@ -38,9 +40,41 @@ GIT_EXTERN(int) git_commit_create_from_ids(
const char *message_encoding,
const char *message,
const git_oid *tree,
- int parent_count,
+ size_t parent_count,
const git_oid *parents[]);
+/**
+ * Callback function to return parents for commit.
+ *
+ * This is invoked with the count of the number of parents processed so far
+ * along with the user supplied payload. This should return a git_oid of
+ * the next parent or NULL if all parents have been provided.
+ */
+typedef const git_oid *(*git_commit_parent_callback)(size_t idx, void *payload);
+
+/**
+ * Create a new commit in the repository with an callback to supply parents.
+ *
+ * See documentation for `git_commit_create()` for information about the
+ * parameters, as the meaning is identical excepting that `tree` takes a
+ * `git_oid` and doesn't check for validity, and `parent_cb` is invoked
+ * with `parent_payload` and should return `git_oid` values or NULL to
+ * indicate that all parents are accounted for.
+ *
+ * @see git_commit_create
+ */
+GIT_EXTERN(int) git_commit_create_from_callback(
+ git_oid *id,
+ 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,
+ git_commit_parent_callback parent_cb,
+ void *parent_payload);
+
/** @} */
GIT_END_DECL
#endif