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