Skip to content

Commit 0d06bf4

Browse files
committed
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 parent 3a8ef82 commit 0d06bf4

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

include/git2/commit.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,21 @@ GIT_EXTERN(int) git_commit_create_with_signature(
501501
*/
502502
GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source);
503503

504+
/**
505+
* Commit signing callback.
506+
*
507+
* The callback will be called with the commit content, giving a user an
508+
* opportunity to sign the commit content. The signature_field
509+
* buf may be left empty to specify the default field.
510+
*
511+
* When the callback:
512+
* - returns GIT_PASSTHROUGH, no signature will be added to the commit.
513+
* - returns < 0, commit creation will be aborted.
514+
* - returns GIT_OK, the signature parameter is expected to be filled.
515+
*/
516+
typedef int (*git_commit_signing_cb)(
517+
git_buf *signature, git_buf *signature_field, const char *commit_content, void *payload);
518+
504519
/** @} */
505520
GIT_END_DECL
506521
#endif

include/git2/rebase.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,6 @@
2323
*/
2424
GIT_BEGIN_DECL
2525

26-
/**
27-
* Rebase commit signature callback.
28-
*
29-
* The callback will be called with the commit content, giving a user an
30-
* opportunity to sign the commit content in a rebase. The signature_field
31-
* buf may be left empty to specify the default field.
32-
*
33-
* When the callback:
34-
* - returns GIT_PASSTHROUGH, no signature will be added to the commit.
35-
* - returns < 0, git_rebase_commit will be aborted.
36-
* - returns GIT_OK, the signature parameter is expected to be filled.
37-
*/
38-
typedef int (*git_rebase_commit_signature_cb)(
39-
git_buf *signature, git_buf *signature_field, const char *commit_content, void *payload);
40-
4126
/**
4227
* Rebase options
4328
*
@@ -95,7 +80,7 @@ typedef struct {
9580
* without a signature.
9681
* This field is only used when performing git_rebase_commit.
9782
*/
98-
git_rebase_commit_signature_cb signature_cb;
83+
git_commit_signing_cb signing_cb;
9984

10085
/**
10186
* This will be passed to each of the callbacks in this struct

src/rebase.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,12 @@ static int rebase_commit__create(
981981
/* this error will be cleared by the signing process, but should be set
982982
* to signal the unsigned commit create process if we are not going to sign */
983983
error = GIT_PASSTHROUGH;
984-
if (rebase->options.signature_cb) {
984+
if (rebase->options.signing_cb) {
985985
if ((error = git_commit_create_buffer(&commit_content, rebase->repo, author, committer,
986986
message_encoding, message, tree, 1, (const git_commit **)&parent_commit)) < 0)
987987
goto done;
988988

989-
if ((error = rebase->options.signature_cb(&commit_signature, &signature_field,
989+
if ((error = rebase->options.signing_cb(&commit_signature, &signature_field,
990990
git_buf_cstr(&commit_content), rebase->options.payload)) < 0 &&
991991
error != GIT_PASSTHROUGH)
992992
goto done;

tests/rebase/sign.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
2525
\n\
2626
Modification 3 to gravy\n";
2727

28-
int signature_cb_passthrough(
28+
int signing_cb_passthrough(
2929
git_buf *signature,
3030
git_buf *signature_field,
3131
const char *commit_content,
@@ -39,7 +39,7 @@ int signature_cb_passthrough(
3939
}
4040

4141
/* git checkout gravy ; git rebase --merge veal */
42-
void test_rebase_sign__passthrough_signature_cb(void)
42+
void test_rebase_sign__passthrough_signing_cb(void)
4343
{
4444
git_rebase *rebase;
4545
git_reference *branch_ref, *upstream_ref;
@@ -54,7 +54,7 @@ parent f87d14a4a236582a0278a916340a793714256864\n\
5454
author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
5555
committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
5656

57-
rebase_opts.signature_cb = signature_cb_passthrough;
57+
rebase_opts.signing_cb = signing_cb_passthrough;
5858

5959
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
6060
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
@@ -84,7 +84,7 @@ committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
8484
git_rebase_free(rebase);
8585
}
8686

87-
int signature_cb_gpg(
87+
int signing_cb_gpg(
8888
git_buf *signature,
8989
git_buf *signature_field,
9090
const char *commit_content,
@@ -148,7 +148,7 @@ gpgsig -----BEGIN PGP SIGNATURE-----\n\
148148
=KbsY\n\
149149
-----END PGP SIGNATURE-----\n";
150150

151-
rebase_opts.signature_cb = signature_cb_gpg;
151+
rebase_opts.signing_cb = signing_cb_gpg;
152152

153153
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
154154
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
@@ -179,14 +179,14 @@ gpgsig -----BEGIN PGP SIGNATURE-----\n\
179179
}
180180

181181

182-
int signature_cb_magic_field(
182+
int signing_cb_magic_field(
183183
git_buf *signature,
184184
git_buf *signature_field,
185185
const char *commit_content,
186186
void *payload)
187187
{
188188
const char *signature_content = "magic word: pretty please";
189-
const char * signature_field_content = "magicsig";
189+
const char *signature_field_content = "magicsig";
190190

191191
cl_assert_equal_b(false, git_buf_is_allocated(signature));
192192
cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
@@ -218,7 +218,7 @@ author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
218218
committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
219219
magicsig magic word: pretty please\n";
220220

221-
rebase_opts.signature_cb = signature_cb_magic_field;
221+
rebase_opts.signing_cb = signing_cb_magic_field;
222222

223223
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
224224
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));

0 commit comments

Comments
 (0)