diff --git a/include/git2/commit.h b/include/git2/commit.h index 7e0409cc7..a50ff58ce 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 f82aedf90..a13873c99 100644 --- a/include/git2/rebase.h +++ b/include/git2/rebase.h @@ -23,21 +23,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 * @@ -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 288af70ec..10a4b80c0 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 d10a66b88..422167678 100644 --- a/tests/rebase/sign.c +++ b/tests/rebase/sign.c @@ -25,7 +25,7 @@ committer Rebaser 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 1405625055 -0400\n\ committer Rebaser 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 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 1405625055 -0400\n\ committer Rebaser 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"));