@@ -943,6 +943,52 @@ int git_rebase_inmemory_index(
943943 return 0 ;
944944}
945945
946+ static int create_signed (
947+ git_oid * out ,
948+ git_rebase * rebase ,
949+ const git_signature * author ,
950+ const git_signature * committer ,
951+ const char * message_encoding ,
952+ const char * message ,
953+ git_tree * tree ,
954+ size_t parent_count ,
955+ const git_commit * * parents )
956+ {
957+ git_buf commit_content = GIT_BUF_INIT ,
958+ commit_signature = GIT_BUF_INIT ,
959+ signature_field = GIT_BUF_INIT ;
960+ int error ;
961+
962+ git_error_clear ();
963+
964+ if ((error = git_commit_create_buffer (& commit_content ,
965+ rebase -> repo , author , committer , message_encoding ,
966+ message , tree , parent_count , parents )) < 0 )
967+ goto done ;
968+
969+ error = rebase -> options .signing_cb (& commit_signature ,
970+ & signature_field , commit_content .ptr ,
971+ rebase -> options .payload );
972+
973+ if (error ) {
974+ if (error != GIT_PASSTHROUGH )
975+ git_error_set_after_callback_function (error , "signing_cb" );
976+
977+ goto done ;
978+ }
979+
980+ error = git_commit_create_with_signature (out , rebase -> repo ,
981+ commit_content .ptr ,
982+ commit_signature .size > 0 ? commit_signature .ptr : NULL ,
983+ signature_field .size > 0 ? signature_field .ptr : NULL );
984+
985+ done :
986+ git_buf_dispose (& commit_signature );
987+ git_buf_dispose (& signature_field );
988+ git_buf_dispose (& commit_content );
989+ return error ;
990+ }
991+
946992static int rebase_commit__create (
947993 git_commit * * out ,
948994 git_rebase * rebase ,
@@ -957,10 +1003,6 @@ static int rebase_commit__create(
9571003 git_commit * current_commit = NULL , * commit = NULL ;
9581004 git_tree * parent_tree = NULL , * tree = NULL ;
9591005 git_oid tree_id , commit_id ;
960- git_buf commit_content = GIT_BUF_INIT , commit_signature = GIT_BUF_INIT ,
961- signature_field = GIT_BUF_INIT ;
962- const char * signature_field_string = NULL ,
963- * commit_signature_string = NULL ;
9641006 int error ;
9651007
9661008 operation = git_array_get (rebase -> operations , rebase -> current );
@@ -991,37 +1033,29 @@ static int rebase_commit__create(
9911033 message = git_commit_message (current_commit );
9921034 }
9931035
994- if ((error = git_commit_create_buffer (& commit_content , rebase -> repo , author , committer ,
995- message_encoding , message , tree , 1 , (const git_commit * * )& parent_commit )) < 0 )
996- goto done ;
997-
998- if (rebase -> options .signing_cb ) {
999- git_error_clear ();
1000- error = git_error_set_after_callback_function (rebase -> options .signing_cb (
1001- & commit_signature , & signature_field , git_buf_cstr (& commit_content ),
1002- rebase -> options .payload ), "commit signing_cb failed" );
1003- if (error == GIT_PASSTHROUGH ) {
1004- git_buf_dispose (& commit_signature );
1005- git_buf_dispose (& signature_field );
1006- git_error_clear ();
1007- error = GIT_OK ;
1008- } else if (error < 0 )
1009- goto done ;
1010- }
1011-
1012- if (git_buf_is_allocated (& commit_signature )) {
1013- GIT_ASSERT (git_buf_contains_nul (& commit_signature ));
1014- commit_signature_string = git_buf_cstr (& commit_signature );
1036+ git_error_clear ();
1037+ error = GIT_PASSTHROUGH ;
1038+
1039+ if (rebase -> options .commit_create_cb ) {
1040+ error = rebase -> options .commit_create_cb (& commit_id ,
1041+ author , committer , message_encoding , message ,
1042+ tree , 1 , (const git_commit * * )& parent_commit ,
1043+ rebase -> options .payload );
1044+
1045+ git_error_set_after_callback_function (error ,
1046+ "commit_create_cb" );
1047+ } else if (rebase -> options .signing_cb ) {
1048+ error = create_signed (& commit_id , rebase , author ,
1049+ committer , message_encoding , message , tree ,
1050+ 1 , (const git_commit * * )& parent_commit );
10151051 }
10161052
1017- if (git_buf_is_allocated ( & signature_field )) {
1018- GIT_ASSERT ( git_buf_contains_nul ( & signature_field ));
1019- signature_field_string = git_buf_cstr ( & signature_field );
1020- }
1053+ if (error == GIT_PASSTHROUGH )
1054+ error = git_commit_create ( & commit_id , rebase -> repo , NULL ,
1055+ author , committer , message_encoding , message ,
1056+ tree , 1 , ( const git_commit * * ) & parent_commit );
10211057
1022- if ((error = git_commit_create_with_signature (& commit_id , rebase -> repo ,
1023- git_buf_cstr (& commit_content ), commit_signature_string ,
1024- signature_field_string )))
1058+ if (error )
10251059 goto done ;
10261060
10271061 if ((error = git_commit_lookup (& commit , rebase -> repo , & commit_id )) < 0 )
@@ -1033,9 +1067,6 @@ static int rebase_commit__create(
10331067 if (error < 0 )
10341068 git_commit_free (commit );
10351069
1036- git_buf_dispose (& commit_signature );
1037- git_buf_dispose (& signature_field );
1038- git_buf_dispose (& commit_content );
10391070 git_commit_free (current_commit );
10401071 git_tree_free (parent_tree );
10411072 git_tree_free (tree );
0 commit comments