Skip to content

Commit ef03e15

Browse files
committed
rebase: deprecate signing_cb
The signing callback should not be used; instead, callers should provide a commit_create_cb, perform the signing and commit creation themselves.
1 parent d3bdf33 commit ef03e15

File tree

5 files changed

+63
-34
lines changed

5 files changed

+63
-34
lines changed

include/git2/commit.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -539,27 +539,6 @@ typedef int (*git_commit_create_cb)(
539539
const git_commit *parents[],
540540
void *payload);
541541

542-
/**
543-
* Commit signing callback.
544-
*
545-
* The callback will be called with the commit content, giving a user an
546-
* opportunity to sign the commit content. The signature_field
547-
* buf may be left empty to specify the default field "gpgsig".
548-
*
549-
* Signatures can take the form of any string, and can be created on an arbitrary
550-
* header field. Signatures are most commonly used for verifying authorship of a
551-
* commit using GPG or a similar cryptographically secure signing algorithm.
552-
* See https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work for more
553-
* details.
554-
*
555-
* When the callback:
556-
* - returns GIT_PASSTHROUGH, no signature will be added to the commit.
557-
* - returns < 0, commit creation will be aborted.
558-
* - returns GIT_OK, the signature parameter is expected to be filled.
559-
*/
560-
typedef int (*git_commit_signing_cb)(
561-
git_buf *signature, git_buf *signature_field, const char *commit_content, void *payload);
562-
563542
/** @} */
564543
GIT_END_DECL
565544
#endif

include/git2/deprecated.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ GIT_EXTERN(void) git_buf_free(git_buf *buffer);
205205

206206
/**@}*/
207207

208+
/** @name Deprecated Commit Definitions
209+
*/
210+
/**@{*/
211+
212+
/**
213+
* Provide a commit signature during commit creation.
214+
*
215+
* Callers should instead define a `git_commit_create_cb` that
216+
* generates a commit buffer using `git_commit_create_buffer`, sign
217+
* that buffer and call `git_commit_create_with_signature`.
218+
*
219+
* @deprecated use a `git_commit_create_cb` instead
220+
*/
221+
typedef int (*git_commit_signing_cb)(
222+
git_buf *signature,
223+
git_buf *signature_field,
224+
const char *commit_content,
225+
void *payload);
226+
227+
/**@}*/
228+
208229
/** @name Deprecated Config Functions and Constants
209230
*/
210231
/**@{*/

include/git2/rebase.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,26 @@ typedef struct {
8686
*/
8787
git_commit_create_cb commit_create_cb;
8888

89+
#ifdef GIT_DEPRECATE_HARD
90+
void *reserved;
91+
#else
8992
/**
9093
* If provided, this will be called with the commit content, allowing
9194
* a signature to be added to the rebase commit. Can be skipped with
9295
* GIT_PASSTHROUGH. If GIT_PASSTHROUGH is returned, a commit will be made
9396
* without a signature.
97+
*
9498
* This field is only used when performing git_rebase_commit.
9599
*
96100
* This callback is not invoked if a `git_commit_create_cb` is
97101
* specified.
102+
*
103+
* This callback is deprecated; users should provide a
104+
* creation callback as `commit_create_cb` that produces a
105+
* commit buffer, signs it, and commits it.
98106
*/
99-
git_commit_signing_cb signing_cb;
107+
int (*signing_cb)(git_buf *, git_buf *, const char *, void *);
108+
#endif
100109

101110
/**
102111
* This will be passed to each of the callbacks in this struct

src/rebase.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ int git_rebase_inmemory_index(
943943
return 0;
944944
}
945945

946+
#ifndef GIT_DEPRECATE_HARD
946947
static int create_signed(
947948
git_oid *out,
948949
git_rebase *rebase,
@@ -988,6 +989,7 @@ static int create_signed(
988989
git_buf_dispose(&commit_content);
989990
return error;
990991
}
992+
#endif
991993

992994
static int rebase_commit__create(
993995
git_commit **out,
@@ -1044,11 +1046,14 @@ static int rebase_commit__create(
10441046

10451047
git_error_set_after_callback_function(error,
10461048
"commit_create_cb");
1047-
} else if (rebase->options.signing_cb) {
1049+
}
1050+
#ifndef GIT_DEPRECATE_HARD
1051+
else if (rebase->options.signing_cb) {
10481052
error = create_signed(&commit_id, rebase, author,
10491053
committer, message_encoding, message, tree,
10501054
1, (const git_commit **)&parent_commit);
10511055
}
1056+
#endif
10521057

10531058
if (error == GIT_PASSTHROUGH)
10541059
error = git_commit_create(&commit_id, rebase->repo, NULL,

tests/rebase/sign.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,29 +248,33 @@ void test_rebase_sign__create_propagates_error(void)
248248
git_rebase_free(rebase);
249249
}
250250

251-
static const char *expected_commit_content = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
252-
parent f87d14a4a236582a0278a916340a793714256864\n\
253-
author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
254-
committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
255-
\n\
256-
Modification 3 to gravy\n";
257-
251+
#ifndef GIT_DEPRECATE_HARD
258252
int signing_cb_passthrough(
259253
git_buf *signature,
260254
git_buf *signature_field,
261255
const char *commit_content,
262256
void *payload)
263257
{
258+
static const char *expected_commit_content = "\
259+
tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
260+
parent f87d14a4a236582a0278a916340a793714256864\n\
261+
author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
262+
committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
263+
\n\
264+
Modification 3 to gravy\n";
265+
264266
cl_assert_equal_b(false, git_buf_is_allocated(signature));
265267
cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
266268
cl_assert_equal_s(expected_commit_content, commit_content);
267269
cl_assert_equal_p(NULL, payload);
268270
return GIT_PASSTHROUGH;
269271
}
272+
#endif /* !GIT_DEPRECATE_HARD */
270273

271274
/* git checkout gravy ; git rebase --merge veal */
272275
void test_rebase_sign__passthrough_signing_cb(void)
273276
{
277+
#ifndef GIT_DEPRECATE_HARD
274278
git_rebase *rebase;
275279
git_reference *branch_ref, *upstream_ref;
276280
git_annotated_commit *branch_head, *upstream_head;
@@ -310,15 +314,18 @@ committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n";
310314
git_annotated_commit_free(upstream_head);
311315
git_commit_free(commit);
312316
git_rebase_free(rebase);
317+
#endif /* !GIT_DEPRECATE_HARD */
313318
}
314319

320+
#ifndef GIT_DEPRECATE_HARD
315321
int signing_cb_gpg(
316322
git_buf *signature,
317323
git_buf *signature_field,
318324
const char *commit_content,
319325
void *payload)
320326
{
321-
const char *gpg_signature = "-----BEGIN PGP SIGNATURE-----\n\
327+
const char *gpg_signature = "\
328+
-----BEGIN PGP SIGNATURE-----\n\
322329
\n\
323330
iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
324331
ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
@@ -343,18 +350,21 @@ cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
343350
cl_git_pass(git_buf_set(signature, gpg_signature, strlen(gpg_signature) + 1));
344351
return GIT_OK;
345352
}
353+
#endif /* !GIT_DEPRECATE_HARD */
346354

347355
/* git checkout gravy ; git rebase --merge veal */
348356
void test_rebase_sign__gpg_with_no_field(void)
349357
{
358+
#ifndef GIT_DEPRECATE_HARD
350359
git_rebase *rebase;
351360
git_reference *branch_ref, *upstream_ref;
352361
git_annotated_commit *branch_head, *upstream_head;
353362
git_rebase_operation *rebase_operation;
354363
git_oid commit_id, expected_id;
355364
git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
356365
git_commit *commit;
357-
const char *expected_commit_raw_header = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
366+
const char *expected_commit_raw_header = "\
367+
tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
358368
parent f87d14a4a236582a0278a916340a793714256864\n\
359369
author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
360370
committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
@@ -402,9 +412,11 @@ gpgsig -----BEGIN PGP SIGNATURE-----\n\
402412
git_annotated_commit_free(upstream_head);
403413
git_commit_free(commit);
404414
git_rebase_free(rebase);
415+
#endif /* !GIT_DEPRECATE_HARD */
405416
}
406417

407418

419+
#ifndef GIT_DEPRECATE_HARD
408420
int signing_cb_magic_field(
409421
git_buf *signature,
410422
git_buf *signature_field,
@@ -426,18 +438,21 @@ int signing_cb_magic_field(
426438

427439
return GIT_OK;
428440
}
441+
#endif /* !GIT_DEPRECATE_HARD */
429442

430443
/* git checkout gravy ; git rebase --merge veal */
431444
void test_rebase_sign__custom_signature_field(void)
432445
{
446+
#ifndef GIT_DEPRECATE_HARD
433447
git_rebase *rebase;
434448
git_reference *branch_ref, *upstream_ref;
435449
git_annotated_commit *branch_head, *upstream_head;
436450
git_rebase_operation *rebase_operation;
437451
git_oid commit_id, expected_id;
438452
git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
439453
git_commit *commit;
440-
const char *expected_commit_raw_header = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
454+
const char *expected_commit_raw_header = "\
455+
tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
441456
parent f87d14a4a236582a0278a916340a793714256864\n\
442457
author Edward Thomson <ethomson@edwardthomson.com> 1405625055 -0400\n\
443458
committer Rebaser <rebaser@rebaser.rb> 1405694510 +0000\n\
@@ -470,5 +485,5 @@ magicsig magic word: pretty please\n";
470485
git_annotated_commit_free(upstream_head);
471486
git_commit_free(commit);
472487
git_rebase_free(rebase);
488+
#endif /* !GIT_DEPRECATE_HARD */
473489
}
474-

0 commit comments

Comments
 (0)