@@ -602,6 +602,12 @@ N_("you have staged changes in your working tree\n"
602
602
"\n"
603
603
" git rebase --continue\n" );
604
604
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
+
605
611
/*
606
612
* If we are cherry-pick, and if the merge did not result in
607
613
* 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"
615
621
* author metadata.
616
622
*/
617
623
static 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 )
620
625
{
621
626
struct child_process cmd = CHILD_PROCESS_INIT ;
622
627
const char * value ;
623
628
624
629
cmd .git_cmd = 1 ;
625
630
626
631
if (is_rebase_i (opts )) {
627
- if (!edit ) {
632
+ if (!( flags & EDIT_MSG ) ) {
628
633
cmd .stdout_to_stderr = 1 ;
629
634
cmd .err = -1 ;
630
635
}
@@ -638,26 +643,27 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
638
643
}
639
644
640
645
argv_array_push (& cmd .args , "commit" );
641
- argv_array_push (& cmd .args , "-n" );
642
646
643
- if (amend )
647
+ if (!(flags & VERIFY_MSG ))
648
+ argv_array_push (& cmd .args , "-n" );
649
+ if ((flags & AMEND_MSG ))
644
650
argv_array_push (& cmd .args , "--amend" );
645
651
if (opts -> gpg_sign )
646
652
argv_array_pushf (& cmd .args , "-S%s" , opts -> gpg_sign );
647
653
if (opts -> signoff )
648
654
argv_array_push (& cmd .args , "-s" );
649
655
if (defmsg )
650
656
argv_array_pushl (& cmd .args , "-F" , defmsg , NULL );
651
- if (cleanup_commit_message )
657
+ if (( flags & CLEANUP_MSG ) )
652
658
argv_array_push (& cmd .args , "--cleanup=strip" );
653
- if (edit )
659
+ if (( flags & EDIT_MSG ) )
654
660
argv_array_push (& cmd .args , "-e" );
655
- else if (!cleanup_commit_message &&
661
+ else if (!( flags & CLEANUP_MSG ) &&
656
662
!opts -> signoff && !opts -> record_origin &&
657
663
git_config_get_value ("commit.cleanup" , & value ))
658
664
argv_array_push (& cmd .args , "--cleanup=verbatim" );
659
665
660
- if (allow_empty )
666
+ if (( flags & ALLOW_EMPTY ) )
661
667
argv_array_push (& cmd .args , "--allow-empty" );
662
668
663
669
if (opts -> allow_empty_message )
@@ -926,14 +932,14 @@ static void record_in_rewritten(struct object_id *oid,
926
932
static int do_pick_commit (enum todo_command command , struct commit * commit ,
927
933
struct replay_opts * opts , int final_fixup )
928
934
{
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 ();
931
937
unsigned char head [20 ];
932
938
struct commit * base , * next , * parent ;
933
939
const char * base_label , * next_label ;
934
940
struct commit_message msg = { NULL , NULL , NULL , NULL };
935
941
struct strbuf msgbuf = STRBUF_INIT ;
936
- int res , unborn = 0 , amend = 0 , allow = 0 ;
942
+ int res , unborn = 0 , allow ;
937
943
938
944
if (opts -> no_commit ) {
939
945
/*
@@ -991,7 +997,9 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
991
997
opts );
992
998
if (res || command != TODO_REWORD )
993
999
goto leave ;
994
- edit = amend = 1 ;
1000
+ flags |= EDIT_MSG | AMEND_MSG ;
1001
+ if (command == TODO_REWORD )
1002
+ flags |= VERIFY_MSG ;
995
1003
msg_file = NULL ;
996
1004
goto fast_forward_edit ;
997
1005
}
@@ -1046,15 +1054,15 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
1046
1054
}
1047
1055
1048
1056
if (command == TODO_REWORD )
1049
- edit = 1 ;
1057
+ flags |= EDIT_MSG | VERIFY_MSG ;
1050
1058
else if (is_fixup (command )) {
1051
1059
if (update_squash_messages (command , commit , opts ))
1052
1060
return -1 ;
1053
- amend = 1 ;
1061
+ flags |= AMEND_MSG ;
1054
1062
if (!final_fixup )
1055
1063
msg_file = rebase_path_squash_msg ();
1056
1064
else if (file_exists (rebase_path_fixup_msg ())) {
1057
- cleanup_commit_message = 1 ;
1065
+ flags |= CLEANUP_MSG ;
1058
1066
msg_file = rebase_path_fixup_msg ();
1059
1067
} else {
1060
1068
const char * dest = git_path ("SQUASH_MSG" );
@@ -1064,7 +1072,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
1064
1072
rebase_path_squash_msg (), dest );
1065
1073
unlink (git_path ("MERGE_MSG" ));
1066
1074
msg_file = dest ;
1067
- edit = 1 ;
1075
+ flags |= EDIT_MSG ;
1068
1076
}
1069
1077
}
1070
1078
@@ -1123,11 +1131,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
1123
1131
if (allow < 0 ) {
1124
1132
res = allow ;
1125
1133
goto leave ;
1126
- }
1134
+ } else if (allow )
1135
+ flags |= ALLOW_EMPTY ;
1127
1136
if (!opts -> no_commit )
1128
1137
fast_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 );
1131
1139
1132
1140
if (!res && final_fixup ) {
1133
1141
unlink (rebase_path_fixup_msg ());
@@ -2154,7 +2162,7 @@ static int continue_single_pick(void)
2154
2162
2155
2163
static int commit_staged_changes (struct replay_opts * opts )
2156
2164
{
2157
- int amend = 0 ;
2165
+ unsigned int flags = ALLOW_EMPTY | EDIT_MSG ;
2158
2166
2159
2167
if (has_unstaged_changes (1 ))
2160
2168
return error (_ ("cannot rebase: You have unstaged changes." ));
@@ -2184,10 +2192,10 @@ static int commit_staged_changes(struct replay_opts *opts)
2184
2192
"--continue' again." ));
2185
2193
2186
2194
strbuf_release (& rev );
2187
- amend = 1 ;
2195
+ flags |= AMEND_MSG ;
2188
2196
}
2189
2197
2190
- if (run_git_commit (rebase_path_message (), opts , 1 , 1 , amend , 0 ))
2198
+ if (run_git_commit (rebase_path_message (), opts , flags ))
2191
2199
return error (_ ("could not commit staged changes." ));
2192
2200
unlink (rebase_path_amend ());
2193
2201
return 0 ;
0 commit comments