@@ -943,6 +943,54 @@ int git_rebase_inmemory_index(
943943 return 0 ;
944944}
945945
946+ #ifndef GIT_DEPRECATE_HARD
947+ static int create_signed (
948+ git_oid * out ,
949+ git_rebase * rebase ,
950+ const git_signature * author ,
951+ const git_signature * committer ,
952+ const char * message_encoding ,
953+ const char * message ,
954+ git_tree * tree ,
955+ size_t parent_count ,
956+ const git_commit * * parents )
957+ {
958+ git_buf commit_content = GIT_BUF_INIT ,
959+ commit_signature = GIT_BUF_INIT ,
960+ signature_field = GIT_BUF_INIT ;
961+ int error ;
962+
963+ git_error_clear ();
964+
965+ if ((error = git_commit_create_buffer (& commit_content ,
966+ rebase -> repo , author , committer , message_encoding ,
967+ message , tree , parent_count , parents )) < 0 )
968+ goto done ;
969+
970+ error = rebase -> options .signing_cb (& commit_signature ,
971+ & signature_field , commit_content .ptr ,
972+ rebase -> options .payload );
973+
974+ if (error ) {
975+ if (error != GIT_PASSTHROUGH )
976+ git_error_set_after_callback_function (error , "signing_cb" );
977+
978+ goto done ;
979+ }
980+
981+ error = git_commit_create_with_signature (out , rebase -> repo ,
982+ commit_content .ptr ,
983+ commit_signature .size > 0 ? commit_signature .ptr : NULL ,
984+ signature_field .size > 0 ? signature_field .ptr : NULL );
985+
986+ done :
987+ git_buf_dispose (& commit_signature );
988+ git_buf_dispose (& signature_field );
989+ git_buf_dispose (& commit_content );
990+ return error ;
991+ }
992+ #endif
993+
946994static int rebase_commit__create (
947995 git_commit * * out ,
948996 git_rebase * rebase ,
@@ -957,10 +1005,6 @@ static int rebase_commit__create(
9571005 git_commit * current_commit = NULL , * commit = NULL ;
9581006 git_tree * parent_tree = NULL , * tree = NULL ;
9591007 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 ;
9641008 int error ;
9651009
9661010 operation = git_array_get (rebase -> operations , rebase -> current );
@@ -991,37 +1035,32 @@ static int rebase_commit__create(
9911035 message = git_commit_message (current_commit );
9921036 }
9931037
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 ;
1038+ git_error_clear ();
1039+ error = GIT_PASSTHROUGH ;
9971040
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- }
1041+ if (rebase -> options .commit_create_cb ) {
1042+ error = rebase -> options .commit_create_cb (& commit_id ,
1043+ author , committer , message_encoding , message ,
1044+ tree , 1 , (const git_commit * * )& parent_commit ,
1045+ rebase -> options .payload );
10111046
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 );
1047+ git_error_set_after_callback_function (error ,
1048+ "commit_create_cb" );
10151049 }
1016-
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 );
1050+ #ifndef GIT_DEPRECATE_HARD
1051+ else if (rebase -> options .signing_cb ) {
1052+ error = create_signed (& commit_id , rebase , author ,
1053+ committer , message_encoding , message , tree ,
1054+ 1 , (const git_commit * * )& parent_commit );
10201055 }
1056+ #endif
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 == GIT_PASSTHROUGH )
1059+ error = git_commit_create (& commit_id , rebase -> repo , NULL ,
1060+ author , committer , message_encoding , message ,
1061+ tree , 1 , (const git_commit * * )& parent_commit );
1062+
1063+ if (error )
10251064 goto done ;
10261065
10271066 if ((error = git_commit_lookup (& commit , rebase -> repo , & commit_id )) < 0 )
@@ -1033,9 +1072,6 @@ static int rebase_commit__create(
10331072 if (error < 0 )
10341073 git_commit_free (commit );
10351074
1036- git_buf_dispose (& commit_signature );
1037- git_buf_dispose (& signature_field );
1038- git_buf_dispose (& commit_content );
10391075 git_commit_free (current_commit );
10401076 git_tree_free (parent_tree );
10411077 git_tree_free (tree );
0 commit comments