@@ -375,6 +375,7 @@ int sequencer_remove_state(struct replay_opts *opts)
375
375
}
376
376
377
377
free (opts -> gpg_sign );
378
+ free (opts -> reflog_action );
378
379
free (opts -> default_strategy );
379
380
free (opts -> strategy );
380
381
for (i = 0 ; i < opts -> xopts_nr ; i ++ )
@@ -1050,6 +1051,8 @@ static int run_git_commit(const char *defmsg,
1050
1051
gpg_opt , gpg_opt );
1051
1052
}
1052
1053
1054
+ strvec_pushf (& cmd .env , GIT_REFLOG_ACTION "=%s" , opts -> reflog_message );
1055
+
1053
1056
if (opts -> committer_date_is_author_date )
1054
1057
strvec_pushf (& cmd .env , "GIT_COMMITTER_DATE=%s" ,
1055
1058
opts -> ignore_date ?
@@ -1589,8 +1592,8 @@ static int try_to_commit(struct repository *r,
1589
1592
goto out ;
1590
1593
}
1591
1594
1592
- if (update_head_with_reflog (current_head , oid ,
1593
- getenv ( "GIT_REFLOG_ACTION" ), msg , & err )) {
1595
+ if (update_head_with_reflog (current_head , oid , opts -> reflog_message ,
1596
+ msg , & err )) {
1594
1597
res = error ("%s" , err .buf );
1595
1598
goto out ;
1596
1599
}
@@ -3674,17 +3677,28 @@ static int do_label(struct repository *r, const char *name, int len)
3674
3677
return ret ;
3675
3678
}
3676
3679
3680
+ static const char * sequencer_reflog_action (struct replay_opts * opts )
3681
+ {
3682
+ if (!opts -> reflog_action ) {
3683
+ opts -> reflog_action = getenv (GIT_REFLOG_ACTION );
3684
+ opts -> reflog_action =
3685
+ xstrdup (opts -> reflog_action ? opts -> reflog_action
3686
+ : action_name (opts ));
3687
+ }
3688
+
3689
+ return opts -> reflog_action ;
3690
+ }
3691
+
3677
3692
__attribute__((format (printf , 3 , 4 )))
3678
3693
static const char * reflog_message (struct replay_opts * opts ,
3679
3694
const char * sub_action , const char * fmt , ...)
3680
3695
{
3681
3696
va_list ap ;
3682
3697
static struct strbuf buf = STRBUF_INIT ;
3683
- char * reflog_action = getenv (GIT_REFLOG_ACTION );
3684
3698
3685
3699
va_start (ap , fmt );
3686
3700
strbuf_reset (& buf );
3687
- strbuf_addstr (& buf , reflog_action ? reflog_action : action_name (opts ));
3701
+ strbuf_addstr (& buf , sequencer_reflog_action (opts ));
3688
3702
if (sub_action )
3689
3703
strbuf_addf (& buf , " (%s)" , sub_action );
3690
3704
if (fmt ) {
@@ -4497,7 +4511,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,
4497
4511
RESET_HEAD_RUN_POST_CHECKOUT_HOOK ,
4498
4512
.head_msg = reflog_message (opts , "start" , "checkout %s" ,
4499
4513
onto_name ),
4500
- .default_reflog_action = "rebase"
4514
+ .default_reflog_action = sequencer_reflog_action ( opts )
4501
4515
};
4502
4516
if (reset_head (r , & ropts )) {
4503
4517
apply_autostash (rebase_path_autostash ());
@@ -4566,11 +4580,8 @@ static int pick_commits(struct repository *r,
4566
4580
struct replay_opts * opts )
4567
4581
{
4568
4582
int res = 0 , reschedule = 0 ;
4569
- char * prev_reflog_action ;
4570
4583
4571
- /* Note that 0 for 3rd parameter of setenv means set only if not set */
4572
- setenv (GIT_REFLOG_ACTION , action_name (opts ), 0 );
4573
- prev_reflog_action = xstrdup (getenv (GIT_REFLOG_ACTION ));
4584
+ opts -> reflog_message = sequencer_reflog_action (opts );
4574
4585
if (opts -> allow_ff )
4575
4586
assert (!(opts -> signoff || opts -> no_commit ||
4576
4587
opts -> record_origin || should_edit (opts ) ||
@@ -4618,14 +4629,12 @@ static int pick_commits(struct repository *r,
4618
4629
}
4619
4630
if (item -> command <= TODO_SQUASH ) {
4620
4631
if (is_rebase_i (opts ))
4621
- setenv ( GIT_REFLOG_ACTION , reflog_message (opts ,
4622
- command_to_string (item -> command ), NULL ),
4623
- 1 );
4632
+ opts -> reflog_message = reflog_message (opts ,
4633
+ command_to_string (item -> command ), NULL );
4634
+
4624
4635
res = do_pick_commit (r , item , opts ,
4625
4636
is_final_fixup (todo_list ),
4626
4637
& check_todo );
4627
- if (is_rebase_i (opts ))
4628
- setenv (GIT_REFLOG_ACTION , prev_reflog_action , 1 );
4629
4638
if (is_rebase_i (opts ) && res < 0 ) {
4630
4639
/* Reschedule */
4631
4640
advise (_ (rescheduled_advice ),
@@ -5050,8 +5059,6 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
5050
5059
if (read_populate_opts (opts ))
5051
5060
return -1 ;
5052
5061
if (is_rebase_i (opts )) {
5053
- char * previous_reflog_action ;
5054
-
5055
5062
if ((res = read_populate_todo (r , & todo_list , opts )))
5056
5063
goto release_todo_list ;
5057
5064
@@ -5062,13 +5069,11 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
5062
5069
unlink (rebase_path_dropped ());
5063
5070
}
5064
5071
5065
- previous_reflog_action = xstrdup (getenv (GIT_REFLOG_ACTION ));
5066
- setenv (GIT_REFLOG_ACTION , reflog_message (opts , "continue" , NULL ), 1 );
5072
+ opts -> reflog_message = reflog_message (opts , "continue" , NULL );
5067
5073
if (commit_staged_changes (r , opts , & todo_list )) {
5068
5074
res = -1 ;
5069
5075
goto release_todo_list ;
5070
5076
}
5071
- setenv (GIT_REFLOG_ACTION , previous_reflog_action , 1 );
5072
5077
} else if (!file_exists (get_todo_path (opts )))
5073
5078
return continue_single_pick (r , opts );
5074
5079
else if ((res = read_populate_todo (r , & todo_list , opts )))
@@ -5116,7 +5121,7 @@ static int single_pick(struct repository *r,
5116
5121
TODO_PICK : TODO_REVERT ;
5117
5122
item .commit = cmit ;
5118
5123
5119
- setenv ( GIT_REFLOG_ACTION , action_name (opts ), 0 );
5124
+ opts -> reflog_message = sequencer_reflog_action (opts );
5120
5125
return do_pick_commit (r , & item , opts , 0 , & check_todo );
5121
5126
}
5122
5127
0 commit comments