summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2017-05-28 00:13:56 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2018-03-22 16:23:20 +0100
commite8eba1cfd86d04fc21c52624aa0b21ab0f9b0cb6 (patch)
tree1272fed90117fef93d17a96e96cdef41fecd8874
parentb31cd43e7edc43c880e209d8ea6e942cf40e7002 (diff)
downloadlibgit2-e8eba1cfd86d04fc21c52624aa0b21ab0f9b0cb6.tar.gz
commit: rearrange _fromstate and _on_head variants
We now have `_fromstate` and `_fromstate_on_head`, the latter of which updates the current branch to point to the new commit.
-rw-r--r--include/git2/commit.h19
-rw-r--r--src/commit.c43
2 files changed, 34 insertions, 28 deletions
diff --git a/include/git2/commit.h b/include/git2/commit.h
index 356b24688..fbe52fecd 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -353,20 +353,20 @@ GIT_EXTERN(int) git_commit_create_on(
const git_commit *parents[]);
/**
- * Create a commit and update the current branch
+ * Create a commit from the current state and update the current branch
*
- * @see git_commit_create
+ * Like `git_commit_create_fromstate`; additionally the current branch will be
+ * updated.
+ *
+ * @see git_commit_create_fromstate
*/
-GIT_EXTERN(int) git_commit_create_on_head(
+GIT_EXTERN(int) git_commit_create_fromstate_on_head(
git_oid *id,
git_repository *repo,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
- const char *message,
- const git_tree *tree,
- size_t parent_count,
- const git_commit *parents[]);
+ const char *message);
/**
* Create new commit in the repository using a variable argument list.
@@ -478,9 +478,8 @@ GIT_EXTERN(int) git_commit_create_buffer(
* variant takes the current state of the repository instead of
* arguments.
*
- * The current branch will be updated. The tree will be created from
- * the repository's index. The parents will be taken from HEAD and
- * MERGE_HEAD, if applicable.
+ * The tree will be created from the repository's index. The parents will be
+ * taken from HEAD and MERGE_HEAD, if applicable.
*
* @see git_commit_create
*/
diff --git a/src/commit.c b/src/commit.c
index 724e014c9..ea881f8fa 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -313,22 +313,6 @@ int git_commit_create_on(
commit_parent_from_array, &data, false);
}
-int git_commit_create_on_head(
- git_oid *id,
- git_repository *repo,
- const git_signature *author,
- const git_signature *committer,
- const char *message_encoding,
- const char *message,
- const git_tree *tree,
- size_t parent_count,
- const git_commit *parents[])
-{
- return git_commit_create_on(id, repo, GIT_HEAD_FILE,
- author, committer, message_encoding, message,
- tree, parent_count, parents);
-}
-
int git_commit_create(
git_oid *id,
git_repository *repo,
@@ -443,9 +427,10 @@ int gather_commit_ids(const git_oid *id, void *payload)
return insert_commit(data->commits, data->repo, id);
}
-int git_commit_create_fromstate(
+static int commit_fromstate(
git_oid *id,
git_repository *repo,
+ const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
@@ -486,7 +471,7 @@ int git_commit_create_fromstate(
if ((error = git_tree_lookup(&tree, repo, &tree_id)) < 0)
goto cleanup;
- error = git_commit_create_on(id, repo, GIT_HEAD_FILE,
+ error = git_commit_create_on(id, repo, update_ref,
author, committer, message_encoding, message,
tree, commits.length, (const git_commit **) commits.contents);
@@ -499,6 +484,28 @@ cleanup:
return 0;
}
+int git_commit_create_fromstate(
+ git_oid *id,
+ git_repository *repo,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message_encoding,
+ const char *message)
+{
+ return commit_fromstate(id, repo, NULL, author, committer, message_encoding, message);
+}
+
+int git_commit_create_fromstate_on_head(
+ git_oid *id,
+ git_repository *repo,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *message_encoding,
+ const char *message)
+{
+ return commit_fromstate(id, repo, GIT_HEAD_FILE, author, committer, message_encoding, message);
+}
+
int git_commit__parse(void *_commit, git_odb_object *odb_obj)
{
git_commit *commit = _commit;