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`.
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
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"));