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