@@ -602,6 +602,12 @@ N_("you have staged changes in your working tree\n"
602602"\n"
603603" git rebase --continue\n" );
604604
605+ #define ALLOW_EMPTY (1<<0)
606+ #define EDIT_MSG (1<<1)
607+ #define AMEND_MSG (1<<2)
608+ #define CLEANUP_MSG (1<<3)
609+ #define VERIFY_MSG (1<<4)
610+
605611/*
606612 * If we are cherry-pick, and if the merge did not result in
607613 * hand-editing, we will hit this commit and inherit the original
@@ -615,16 +621,15 @@ N_("you have staged changes in your working tree\n"
615621 * author metadata.
616622 */
617623static int run_git_commit (const char * defmsg , struct replay_opts * opts ,
618- int allow_empty , int edit , int amend ,
619- int cleanup_commit_message )
624+ unsigned int flags )
620625{
621626 struct child_process cmd = CHILD_PROCESS_INIT ;
622627 const char * value ;
623628
624629 cmd .git_cmd = 1 ;
625630
626631 if (is_rebase_i (opts )) {
627- if (!edit ) {
632+ if (!( flags & EDIT_MSG ) ) {
628633 cmd .stdout_to_stderr = 1 ;
629634 cmd .err = -1 ;
630635 }
@@ -638,26 +643,27 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
638643 }
639644
640645 argv_array_push (& cmd .args , "commit" );
641- argv_array_push (& cmd .args , "-n" );
642646
643- if (amend )
647+ if (!(flags & VERIFY_MSG ))
648+ argv_array_push (& cmd .args , "-n" );
649+ if ((flags & AMEND_MSG ))
644650 argv_array_push (& cmd .args , "--amend" );
645651 if (opts -> gpg_sign )
646652 argv_array_pushf (& cmd .args , "-S%s" , opts -> gpg_sign );
647653 if (opts -> signoff )
648654 argv_array_push (& cmd .args , "-s" );
649655 if (defmsg )
650656 argv_array_pushl (& cmd .args , "-F" , defmsg , NULL );
651- if (cleanup_commit_message )
657+ if (( flags & CLEANUP_MSG ) )
652658 argv_array_push (& cmd .args , "--cleanup=strip" );
653- if (edit )
659+ if (( flags & EDIT_MSG ) )
654660 argv_array_push (& cmd .args , "-e" );
655- else if (!cleanup_commit_message &&
661+ else if (!( flags & CLEANUP_MSG ) &&
656662 !opts -> signoff && !opts -> record_origin &&
657663 git_config_get_value ("commit.cleanup" , & value ))
658664 argv_array_push (& cmd .args , "--cleanup=verbatim" );
659665
660- if (allow_empty )
666+ if (( flags & ALLOW_EMPTY ) )
661667 argv_array_push (& cmd .args , "--allow-empty" );
662668
663669 if (opts -> allow_empty_message )
@@ -926,14 +932,14 @@ static void record_in_rewritten(struct object_id *oid,
926932static int do_pick_commit (enum todo_command command , struct commit * commit ,
927933 struct replay_opts * opts , int final_fixup )
928934{
929- int edit = opts -> edit , cleanup_commit_message = 0 ;
930- const char * msg_file = edit ? NULL : git_path_merge_msg ();
935+ unsigned int flags = opts -> edit ? EDIT_MSG : 0 ;
936+ const char * msg_file = opts -> edit ? NULL : git_path_merge_msg ();
931937 unsigned char head [20 ];
932938 struct commit * base , * next , * parent ;
933939 const char * base_label , * next_label ;
934940 struct commit_message msg = { NULL , NULL , NULL , NULL };
935941 struct strbuf msgbuf = STRBUF_INIT ;
936- int res , unborn = 0 , amend = 0 , allow = 0 ;
942+ int res , unborn = 0 , allow ;
937943
938944 if (opts -> no_commit ) {
939945 /*
@@ -991,7 +997,9 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
991997 opts );
992998 if (res || command != TODO_REWORD )
993999 goto leave ;
994- edit = amend = 1 ;
1000+ flags |= EDIT_MSG | AMEND_MSG ;
1001+ if (command == TODO_REWORD )
1002+ flags |= VERIFY_MSG ;
9951003 msg_file = NULL ;
9961004 goto fast_forward_edit ;
9971005 }
@@ -1046,15 +1054,15 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
10461054 }
10471055
10481056 if (command == TODO_REWORD )
1049- edit = 1 ;
1057+ flags |= EDIT_MSG | VERIFY_MSG ;
10501058 else if (is_fixup (command )) {
10511059 if (update_squash_messages (command , commit , opts ))
10521060 return -1 ;
1053- amend = 1 ;
1061+ flags |= AMEND_MSG ;
10541062 if (!final_fixup )
10551063 msg_file = rebase_path_squash_msg ();
10561064 else if (file_exists (rebase_path_fixup_msg ())) {
1057- cleanup_commit_message = 1 ;
1065+ flags |= CLEANUP_MSG ;
10581066 msg_file = rebase_path_fixup_msg ();
10591067 } else {
10601068 const char * dest = git_path ("SQUASH_MSG" );
@@ -1064,7 +1072,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
10641072 rebase_path_squash_msg (), dest );
10651073 unlink (git_path ("MERGE_MSG" ));
10661074 msg_file = dest ;
1067- edit = 1 ;
1075+ flags |= EDIT_MSG ;
10681076 }
10691077 }
10701078
@@ -1123,11 +1131,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
11231131 if (allow < 0 ) {
11241132 res = allow ;
11251133 goto leave ;
1126- }
1134+ } else if (allow )
1135+ flags |= ALLOW_EMPTY ;
11271136 if (!opts -> no_commit )
11281137fast_forward_edit :
1129- res = run_git_commit (msg_file , opts , allow , edit , amend ,
1130- cleanup_commit_message );
1138+ res = run_git_commit (msg_file , opts , flags );
11311139
11321140 if (!res && final_fixup ) {
11331141 unlink (rebase_path_fixup_msg ());
@@ -2154,7 +2162,7 @@ static int continue_single_pick(void)
21542162
21552163static int commit_staged_changes (struct replay_opts * opts )
21562164{
2157- int amend = 0 ;
2165+ unsigned int flags = ALLOW_EMPTY | EDIT_MSG ;
21582166
21592167 if (has_unstaged_changes (1 ))
21602168 return error (_ ("cannot rebase: You have unstaged changes." ));
@@ -2184,10 +2192,10 @@ static int commit_staged_changes(struct replay_opts *opts)
21842192 "--continue' again." ));
21852193
21862194 strbuf_release (& rev );
2187- amend = 1 ;
2195+ flags |= AMEND_MSG ;
21882196 }
21892197
2190- if (run_git_commit (rebase_path_message (), opts , 1 , 1 , amend , 0 ))
2198+ if (run_git_commit (rebase_path_message (), opts , flags ))
21912199 return error (_ ("could not commit staged changes." ));
21922200 unlink (rebase_path_amend ());
21932201 return 0 ;
0 commit comments