Commit 0d06bf4852a3b943a40c6378f638b7f0bb8972b9

Tyler Wanek 2019-01-24T08:42:25

fixup: More generic signing_cb for future flexibility In the case that we want to build merge + commit, cherrypick + commit, or even just build a commit with signing callback, `git_rebase_commit_signature_cb` particular callback should be made more generic. We also renamed `signature_cb` to `signing_cb` to improve clarity on the purpose of the callback (build a difference between a git_signature and the act of signing). So we've ended up with `git_commit_signing_cb`.

diff --git a/include/git2/commit.h b/include/git2/commit.h
index 7e0409c..a50ff58 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -501,6 +501,21 @@ GIT_EXTERN(int) git_commit_create_with_signature(
  */
 GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source);
 
+/**
+ * Commit signing callback.
+ *
+ * The callback will be called with the commit content, giving a user an
+ * opportunity to sign the commit content. The signature_field
+ * buf may be left empty to specify the default field.
+ *
+ * When the callback:
+ * - returns GIT_PASSTHROUGH, no signature will be added to the commit.
+ * - returns < 0, commit creation will be aborted.
+ * - returns GIT_OK, the signature parameter is expected to be filled.
+ */
+typedef int (*git_commit_signing_cb)(
+	git_buf *signature, git_buf *signature_field, const char *commit_content, void *payload);
+
 /** @} */
 GIT_END_DECL
 #endif
diff --git a/include/git2/rebase.h b/include/git2/rebase.h
index f82aedf..a13873c 100644
--- a/include/git2/rebase.h
+++ b/include/git2/rebase.h
@@ -24,21 +24,6 @@
 GIT_BEGIN_DECL
 
 /**
- * Rebase commit signature callback.
- *
- * The callback will be called with the commit content, giving a user an
- * opportunity to sign the commit content in a rebase. The signature_field
- * buf may be left empty to specify the default field.
- *
- * When the callback:
- * - returns GIT_PASSTHROUGH, no signature will be added to the commit.
- * - returns < 0, git_rebase_commit will be aborted.
- * - returns GIT_OK, the signature parameter is expected to be filled.
- */
-typedef int (*git_rebase_commit_signature_cb)(
-	git_buf *signature, git_buf *signature_field, const char *commit_content, void *payload);
-
-/**
  * Rebase options
  *
  * Use to tell the rebase machinery how to operate.
@@ -95,7 +80,7 @@ typedef struct {
 	 * without a signature.
 	 * This field is only used when performing git_rebase_commit.
 	 */
-	git_rebase_commit_signature_cb signature_cb;
+	git_commit_signing_cb signing_cb;
 
 	/**
 	 * This will be passed to each of the callbacks in this struct
diff --git a/src/rebase.c b/src/rebase.c
index 288af70..10a4b80 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -981,12 +981,12 @@ static int rebase_commit__create(
 	/* this error will be cleared by the signing process, but should be set
 	 * to signal the unsigned commit create process if we are not going to sign */
 	error = GIT_PASSTHROUGH;
-	if (rebase->options.signature_cb) {
+	if (rebase->options.signing_cb) {
 		if ((error = git_commit_create_buffer(&commit_content, rebase->repo, author, committer,
 				message_encoding, message, tree, 1, (const git_commit **)&parent_commit)) < 0)
 			goto done;
 
-		if ((error = rebase->options.signature_cb(&commit_signature, &signature_field,
+		if ((error = rebase->options.signing_cb(&commit_signature, &signature_field,
 				git_buf_cstr(&commit_content), rebase->options.payload)) < 0 &&
 				error != GIT_PASSTHROUGH)
 			goto done;
diff --git a/tests/rebase/sign.c b/tests/rebase/sign.c
index d10a66b..4221676 100644
--- a/tests/rebase/sign.c
+++ b/tests/rebase/sign.c
@@ -25,7 +25,7 @@ committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
 \n\
 Modification 3 to gravy\n";
 
-int signature_cb_passthrough(
+int signing_cb_passthrough(
 	git_buf *signature,
 	git_buf *signature_field,
 	const char *commit_content,
@@ -39,7 +39,7 @@ int signature_cb_passthrough(
 }
 
 /* git checkout gravy ; git rebase --merge veal */
-void test_rebase_sign__passthrough_signature_cb(void)
+void test_rebase_sign__passthrough_signing_cb(void)
 {
 	git_rebase *rebase;
 	git_reference *branch_ref, *upstream_ref;
@@ -54,7 +54,7 @@ parent f87d14a4a236582a0278a916340a793714256864\n\
 author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
 
-	rebase_opts.signature_cb = signature_cb_passthrough;
+	rebase_opts.signing_cb = signing_cb_passthrough;
 
 	cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
 	cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
@@ -84,7 +84,7 @@ committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
 	git_rebase_free(rebase);
 }
 
-int signature_cb_gpg(
+int signing_cb_gpg(
 	git_buf *signature,
 	git_buf *signature_field,
 	const char *commit_content,
@@ -148,7 +148,7 @@ gpgsig -----BEGIN PGP SIGNATURE-----\n\
  =KbsY\n\
  -----END PGP SIGNATURE-----\n";
 
-	rebase_opts.signature_cb = signature_cb_gpg;
+	rebase_opts.signing_cb = signing_cb_gpg;
 
 	cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
 	cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
@@ -179,14 +179,14 @@ gpgsig -----BEGIN PGP SIGNATURE-----\n\
 }
 
 
-int signature_cb_magic_field(
+int signing_cb_magic_field(
 	git_buf *signature,
 	git_buf *signature_field,
 	const char *commit_content,
 	void *payload)
 {
 	const char *signature_content = "magic word: pretty please";
-	const char * signature_field_content = "magicsig";
+	const char *signature_field_content = "magicsig";
 
 	cl_assert_equal_b(false, git_buf_is_allocated(signature));
 	cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
@@ -218,7 +218,7 @@ author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
 committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
 magicsig magic word: pretty please\n";
 
-	rebase_opts.signature_cb = signature_cb_magic_field;
+	rebase_opts.signing_cb = signing_cb_magic_field;
 
 	cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
 	cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));