@@ -868,34 +868,6 @@ static char *get_author(const char *message)
868
868
return NULL ;
869
869
}
870
870
871
- /* Read author-script and return an ident line (author <email> timestamp) */
872
- static const char * read_author_ident (struct strbuf * buf )
873
- {
874
- struct strbuf out = STRBUF_INIT ;
875
- char * name , * email , * date ;
876
-
877
- if (read_author_script (rebase_path_author_script (),
878
- & name , & email , & date , 0 ))
879
- return NULL ;
880
-
881
- /* validate date since fmt_ident() will die() on bad value */
882
- if (parse_date (date , & out )){
883
- warning (_ ("invalid date format '%s' in '%s'" ),
884
- date , rebase_path_author_script ());
885
- strbuf_release (& out );
886
- return NULL ;
887
- }
888
-
889
- strbuf_reset (& out );
890
- strbuf_addstr (& out , fmt_ident (name , email , WANT_AUTHOR_IDENT , date , 0 ));
891
- strbuf_swap (buf , & out );
892
- strbuf_release (& out );
893
- free (name );
894
- free (email );
895
- free (date );
896
- return buf -> buf ;
897
- }
898
-
899
871
static const char staged_changes_advice [] =
900
872
N_ ("you have staged changes in your working tree\n"
901
873
"If these changes are meant to be squashed into the previous commit, run:\n"
@@ -953,47 +925,6 @@ static int run_git_commit(struct repository *r,
953
925
{
954
926
struct child_process cmd = CHILD_PROCESS_INIT ;
955
927
956
- if ((flags & CREATE_ROOT_COMMIT ) && !(flags & AMEND_MSG )) {
957
- struct strbuf msg = STRBUF_INIT , script = STRBUF_INIT ;
958
- const char * author = NULL ;
959
- struct object_id root_commit , * cache_tree_oid ;
960
- int res = 0 ;
961
-
962
- if (is_rebase_i (opts )) {
963
- author = read_author_ident (& script );
964
- if (!author ) {
965
- strbuf_release (& script );
966
- return -1 ;
967
- }
968
- }
969
-
970
- if (!defmsg )
971
- BUG ("root commit without message" );
972
-
973
- if (!(cache_tree_oid = get_cache_tree_oid (r -> index )))
974
- res = -1 ;
975
-
976
- if (!res )
977
- res = strbuf_read_file (& msg , defmsg , 0 );
978
-
979
- if (res <= 0 )
980
- res = error_errno (_ ("could not read '%s'" ), defmsg );
981
- else
982
- res = commit_tree (msg .buf , msg .len , cache_tree_oid ,
983
- NULL , & root_commit , author ,
984
- opts -> gpg_sign );
985
-
986
- strbuf_release (& msg );
987
- strbuf_release (& script );
988
- if (!res ) {
989
- update_ref (NULL , "CHERRY_PICK_HEAD" , & root_commit , NULL ,
990
- REF_NO_DEREF , UPDATE_REFS_MSG_ON_ERR );
991
- res = update_ref (NULL , "HEAD" , & root_commit , NULL , 0 ,
992
- UPDATE_REFS_MSG_ON_ERR );
993
- }
994
- return res < 0 ? error (_ ("writing root commit" )) : 0 ;
995
- }
996
-
997
928
cmd .git_cmd = 1 ;
998
929
999
930
if (is_rebase_i (opts ) && read_env_script (& cmd .env_array )) {
@@ -1377,7 +1308,7 @@ static int try_to_commit(struct repository *r,
1377
1308
struct object_id * oid )
1378
1309
{
1379
1310
struct object_id tree ;
1380
- struct commit * current_head ;
1311
+ struct commit * current_head = NULL ;
1381
1312
struct commit_list * parents = NULL ;
1382
1313
struct commit_extra_header * extra = NULL ;
1383
1314
struct strbuf err = STRBUF_INIT ;
@@ -1412,7 +1343,8 @@ static int try_to_commit(struct repository *r,
1412
1343
}
1413
1344
parents = copy_commit_list (current_head -> parents );
1414
1345
extra = read_commit_extra_headers (current_head , exclude_gpgsig );
1415
- } else if (current_head ) {
1346
+ } else if (current_head &&
1347
+ (!(flags & CREATE_ROOT_COMMIT ) || (flags & AMEND_MSG ))) {
1416
1348
commit_list_insert (current_head , & parents );
1417
1349
}
1418
1350
@@ -1489,8 +1421,7 @@ static int do_commit(struct repository *r,
1489
1421
{
1490
1422
int res = 1 ;
1491
1423
1492
- if (!(flags & EDIT_MSG ) && !(flags & VERIFY_MSG ) &&
1493
- !(flags & CREATE_ROOT_COMMIT )) {
1424
+ if (!(flags & EDIT_MSG ) && !(flags & VERIFY_MSG )) {
1494
1425
struct object_id oid ;
1495
1426
struct strbuf sb = STRBUF_INIT ;
1496
1427
@@ -1774,7 +1705,7 @@ static int do_pick_commit(struct repository *r,
1774
1705
enum todo_command command ,
1775
1706
struct commit * commit ,
1776
1707
struct replay_opts * opts ,
1777
- int final_fixup )
1708
+ int final_fixup , int * check_todo )
1778
1709
{
1779
1710
unsigned int flags = opts -> edit ? EDIT_MSG : 0 ;
1780
1711
const char * msg_file = opts -> edit ? NULL : git_path_merge_msg (r );
@@ -1784,7 +1715,7 @@ static int do_pick_commit(struct repository *r,
1784
1715
char * author = NULL ;
1785
1716
struct commit_message msg = { NULL , NULL , NULL , NULL };
1786
1717
struct strbuf msgbuf = STRBUF_INIT ;
1787
- int res , unborn = 0 , allow ;
1718
+ int res , unborn = 0 , reword = 0 , allow ;
1788
1719
1789
1720
if (opts -> no_commit ) {
1790
1721
/*
@@ -1854,7 +1785,7 @@ static int do_pick_commit(struct repository *r,
1854
1785
opts );
1855
1786
if (res || command != TODO_REWORD )
1856
1787
goto leave ;
1857
- flags |= EDIT_MSG | AMEND_MSG | VERIFY_MSG ;
1788
+ reword = 1 ;
1858
1789
msg_file = NULL ;
1859
1790
goto fast_forward_edit ;
1860
1791
}
@@ -1912,7 +1843,7 @@ static int do_pick_commit(struct repository *r,
1912
1843
}
1913
1844
1914
1845
if (command == TODO_REWORD )
1915
- flags |= EDIT_MSG | VERIFY_MSG ;
1846
+ reword = 1 ;
1916
1847
else if (is_fixup (command )) {
1917
1848
if (update_squash_messages (r , command , commit , opts ))
1918
1849
return -1 ;
@@ -1996,13 +1927,21 @@ static int do_pick_commit(struct repository *r,
1996
1927
} else if (allow )
1997
1928
flags |= ALLOW_EMPTY ;
1998
1929
if (!opts -> no_commit ) {
1999
- fast_forward_edit :
2000
1930
if (author || command == TODO_REVERT || (flags & AMEND_MSG ))
2001
1931
res = do_commit (r , msg_file , author , opts , flags );
2002
1932
else
2003
1933
res = error (_ ("unable to parse commit author" ));
1934
+ * check_todo = !!(flags & EDIT_MSG );
1935
+ if (!res && reword ) {
1936
+ fast_forward_edit :
1937
+ res = run_git_commit (r , NULL , opts , EDIT_MSG |
1938
+ VERIFY_MSG | AMEND_MSG |
1939
+ (flags & ALLOW_EMPTY ));
1940
+ * check_todo = 1 ;
1941
+ }
2004
1942
}
2005
1943
1944
+
2006
1945
if (!res && final_fixup ) {
2007
1946
unlink (rebase_path_fixup_msg ());
2008
1947
unlink (rebase_path_squash_msg ());
@@ -3827,6 +3766,7 @@ static int pick_commits(struct repository *r,
3827
3766
while (todo_list -> current < todo_list -> nr ) {
3828
3767
struct todo_item * item = todo_list -> items + todo_list -> current ;
3829
3768
const char * arg = todo_item_get_arg (todo_list , item );
3769
+ int check_todo = 0 ;
3830
3770
3831
3771
if (save_todo (todo_list , opts ))
3832
3772
return -1 ;
@@ -3865,7 +3805,8 @@ static int pick_commits(struct repository *r,
3865
3805
command_to_string (item -> command ), NULL ),
3866
3806
1 );
3867
3807
res = do_pick_commit (r , item -> command , item -> commit ,
3868
- opts , is_final_fixup (todo_list ));
3808
+ opts , is_final_fixup (todo_list ),
3809
+ & check_todo );
3869
3810
if (is_rebase_i (opts ) && res < 0 ) {
3870
3811
/* Reschedule */
3871
3812
advise (_ (rescheduled_advice ),
@@ -3922,7 +3863,6 @@ static int pick_commits(struct repository *r,
3922
3863
} else if (item -> command == TODO_EXEC ) {
3923
3864
char * end_of_arg = (char * )(arg + item -> arg_len );
3924
3865
int saved = * end_of_arg ;
3925
- struct stat st ;
3926
3866
3927
3867
if (!opts -> verbose )
3928
3868
term_clear_line ();
@@ -3933,17 +3873,8 @@ static int pick_commits(struct repository *r,
3933
3873
if (res ) {
3934
3874
if (opts -> reschedule_failed_exec )
3935
3875
reschedule = 1 ;
3936
- } else if (stat (get_todo_path (opts ), & st ))
3937
- res = error_errno (_ ("could not stat '%s'" ),
3938
- get_todo_path (opts ));
3939
- else if (match_stat_data (& todo_list -> stat , & st )) {
3940
- /* Reread the todo file if it has changed. */
3941
- todo_list_release (todo_list );
3942
- if (read_populate_todo (r , todo_list , opts ))
3943
- res = -1 ; /* message was printed */
3944
- /* `current` will be incremented below */
3945
- todo_list -> current = -1 ;
3946
3876
}
3877
+ check_todo = 1 ;
3947
3878
} else if (item -> command == TODO_LABEL ) {
3948
3879
if ((res = do_label (r , arg , item -> arg_len )))
3949
3880
reschedule = 1 ;
@@ -3979,6 +3910,20 @@ static int pick_commits(struct repository *r,
3979
3910
item -> commit ,
3980
3911
arg , item -> arg_len ,
3981
3912
opts , res , 0 );
3913
+ } else if (check_todo && !res ) {
3914
+ struct stat st ;
3915
+
3916
+ if (stat (get_todo_path (opts ), & st )) {
3917
+ res = error_errno (_ ("could not stat '%s'" ),
3918
+ get_todo_path (opts ));
3919
+ } else if (match_stat_data (& todo_list -> stat , & st )) {
3920
+ /* Reread the todo file if it has changed. */
3921
+ todo_list_release (todo_list );
3922
+ if (read_populate_todo (r , todo_list , opts ))
3923
+ res = -1 ; /* message was printed */
3924
+ /* `current` will be incremented below */
3925
+ todo_list -> current = -1 ;
3926
+ }
3982
3927
}
3983
3928
3984
3929
todo_list -> current ++ ;
@@ -4305,9 +4250,12 @@ static int single_pick(struct repository *r,
4305
4250
struct commit * cmit ,
4306
4251
struct replay_opts * opts )
4307
4252
{
4253
+ int check_todo ;
4254
+
4308
4255
setenv (GIT_REFLOG_ACTION , action_name (opts ), 0 );
4309
4256
return do_pick_commit (r , opts -> action == REPLAY_PICK ?
4310
- TODO_PICK : TODO_REVERT , cmit , opts , 0 );
4257
+ TODO_PICK : TODO_REVERT , cmit , opts , 0 ,
4258
+ & check_todo );
4311
4259
}
4312
4260
4313
4261
int sequencer_pick_revisions (struct repository * r ,
0 commit comments