@@ -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
}
@@ -3672,17 +3675,28 @@ static int do_label(struct repository *r, const char *name, int len)
3672
3675
return ret ;
3673
3676
}
3674
3677
3678
+ static const char * sequencer_reflog_action (struct replay_opts * opts )
3679
+ {
3680
+ if (!opts -> reflog_action ) {
3681
+ opts -> reflog_action = getenv (GIT_REFLOG_ACTION );
3682
+ opts -> reflog_action =
3683
+ xstrdup (opts -> reflog_action ? opts -> reflog_action
3684
+ : action_name (opts ));
3685
+ }
3686
+
3687
+ return opts -> reflog_action ;
3688
+ }
3689
+
3675
3690
__attribute__((format (printf , 3 , 4 )))
3676
3691
static const char * reflog_message (struct replay_opts * opts ,
3677
3692
const char * sub_action , const char * fmt , ...)
3678
3693
{
3679
3694
va_list ap ;
3680
3695
static struct strbuf buf = STRBUF_INIT ;
3681
- char * reflog_action = getenv (GIT_REFLOG_ACTION );
3682
3696
3683
3697
va_start (ap , fmt );
3684
3698
strbuf_reset (& buf );
3685
- strbuf_addstr (& buf , reflog_action ? reflog_action : action_name (opts ));
3699
+ strbuf_addstr (& buf , sequencer_reflog_action (opts ));
3686
3700
if (sub_action )
3687
3701
strbuf_addf (& buf , " (%s)" , sub_action );
3688
3702
if (fmt ) {
@@ -4502,7 +4516,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,
4502
4516
RESET_HEAD_RUN_POST_CHECKOUT_HOOK ,
4503
4517
.head_msg = reflog_message (opts , "start" , "checkout %s" ,
4504
4518
onto_name ),
4505
- .default_reflog_action = "rebase"
4519
+ .default_reflog_action = sequencer_reflog_action ( opts )
4506
4520
};
4507
4521
if (reset_head (r , & ropts )) {
4508
4522
apply_autostash (rebase_path_autostash ());
@@ -4571,11 +4585,8 @@ static int pick_commits(struct repository *r,
4571
4585
struct replay_opts * opts )
4572
4586
{
4573
4587
int res = 0 , reschedule = 0 ;
4574
- char * prev_reflog_action ;
4575
4588
4576
- /* Note that 0 for 3rd parameter of setenv means set only if not set */
4577
- setenv (GIT_REFLOG_ACTION , action_name (opts ), 0 );
4578
- prev_reflog_action = xstrdup (getenv (GIT_REFLOG_ACTION ));
4589
+ opts -> reflog_message = sequencer_reflog_action (opts );
4579
4590
if (opts -> allow_ff )
4580
4591
assert (!(opts -> signoff || opts -> no_commit ||
4581
4592
opts -> record_origin || should_edit (opts ) ||
@@ -4623,14 +4634,12 @@ static int pick_commits(struct repository *r,
4623
4634
}
4624
4635
if (item -> command <= TODO_SQUASH ) {
4625
4636
if (is_rebase_i (opts ))
4626
- setenv ( GIT_REFLOG_ACTION , reflog_message (opts ,
4627
- command_to_string (item -> command ), NULL ),
4628
- 1 );
4637
+ opts -> reflog_message = reflog_message (opts ,
4638
+ command_to_string (item -> command ), NULL );
4639
+
4629
4640
res = do_pick_commit (r , item , opts ,
4630
4641
is_final_fixup (todo_list ),
4631
4642
& check_todo );
4632
- if (is_rebase_i (opts ))
4633
- setenv (GIT_REFLOG_ACTION , prev_reflog_action , 1 );
4634
4643
if (is_rebase_i (opts ) && res < 0 ) {
4635
4644
/* Reschedule */
4636
4645
advise (_ (rescheduled_advice ),
@@ -5053,8 +5062,6 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
5053
5062
if (read_populate_opts (opts ))
5054
5063
return -1 ;
5055
5064
if (is_rebase_i (opts )) {
5056
- char * previous_reflog_action ;
5057
-
5058
5065
if ((res = read_populate_todo (r , & todo_list , opts )))
5059
5066
goto release_todo_list ;
5060
5067
@@ -5065,13 +5072,11 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
5065
5072
unlink (rebase_path_dropped ());
5066
5073
}
5067
5074
5068
- previous_reflog_action = xstrdup (getenv (GIT_REFLOG_ACTION ));
5069
- setenv (GIT_REFLOG_ACTION , reflog_message (opts , "continue" , NULL ), 1 );
5075
+ opts -> reflog_message = reflog_message (opts , "continue" , NULL );
5070
5076
if (commit_staged_changes (r , opts , & todo_list )) {
5071
5077
res = -1 ;
5072
5078
goto release_todo_list ;
5073
5079
}
5074
- setenv (GIT_REFLOG_ACTION , previous_reflog_action , 1 );
5075
5080
} else if (!file_exists (get_todo_path (opts )))
5076
5081
return continue_single_pick (r , opts );
5077
5082
else if ((res = read_populate_todo (r , & todo_list , opts )))
@@ -5119,7 +5124,7 @@ static int single_pick(struct repository *r,
5119
5124
TODO_PICK : TODO_REVERT ;
5120
5125
item .commit = cmit ;
5121
5126
5122
- setenv ( GIT_REFLOG_ACTION , action_name (opts ), 0 );
5127
+ opts -> reflog_message = sequencer_reflog_action (opts );
5123
5128
return do_pick_commit (r , & item , opts , 0 , & check_todo );
5124
5129
}
5125
5130
0 commit comments