@@ -224,11 +224,6 @@ struct replay_ctx {
224
224
* current chain.
225
225
*/
226
226
struct strbuf current_fixups ;
227
- /*
228
- * Stores the reflog message that will be used when creating a
229
- * commit. Points to a static buffer and should not be free()'d.
230
- */
231
- const char * reflog_message ;
232
227
/*
233
228
* The number of completed fixup and squash commands in the
234
229
* current chain.
@@ -1124,10 +1119,10 @@ static int run_command_silent_on_success(struct child_process *cmd)
1124
1119
* author metadata.
1125
1120
*/
1126
1121
static int run_git_commit (const char * defmsg ,
1122
+ const char * reflog_action ,
1127
1123
struct replay_opts * opts ,
1128
1124
unsigned int flags )
1129
1125
{
1130
- struct replay_ctx * ctx = opts -> ctx ;
1131
1126
struct child_process cmd = CHILD_PROCESS_INIT ;
1132
1127
1133
1128
if ((flags & CLEANUP_MSG ) && (flags & VERBATIM_MSG ))
@@ -1145,7 +1140,7 @@ static int run_git_commit(const char *defmsg,
1145
1140
gpg_opt , gpg_opt );
1146
1141
}
1147
1142
1148
- strvec_pushf (& cmd .env , GIT_REFLOG_ACTION "=%s" , ctx -> reflog_message );
1143
+ strvec_pushf (& cmd .env , GIT_REFLOG_ACTION "=%s" , reflog_action );
1149
1144
1150
1145
if (opts -> committer_date_is_author_date )
1151
1146
strvec_pushf (& cmd .env , "GIT_COMMITTER_DATE=%s" ,
@@ -1529,10 +1524,10 @@ static int parse_head(struct repository *r, struct commit **head)
1529
1524
*/
1530
1525
static int try_to_commit (struct repository * r ,
1531
1526
struct strbuf * msg , const char * author ,
1527
+ const char * reflog_action ,
1532
1528
struct replay_opts * opts , unsigned int flags ,
1533
1529
struct object_id * oid )
1534
1530
{
1535
- struct replay_ctx * ctx = opts -> ctx ;
1536
1531
struct object_id tree ;
1537
1532
struct commit * current_head = NULL ;
1538
1533
struct commit_list * parents = NULL ;
@@ -1694,7 +1689,7 @@ static int try_to_commit(struct repository *r,
1694
1689
goto out ;
1695
1690
}
1696
1691
1697
- if (update_head_with_reflog (current_head , oid , ctx -> reflog_message ,
1692
+ if (update_head_with_reflog (current_head , oid , reflog_action ,
1698
1693
msg , & err )) {
1699
1694
res = error ("%s" , err .buf );
1700
1695
goto out ;
@@ -1725,6 +1720,7 @@ static int write_rebase_head(struct object_id *oid)
1725
1720
1726
1721
static int do_commit (struct repository * r ,
1727
1722
const char * msg_file , const char * author ,
1723
+ const char * reflog_action ,
1728
1724
struct replay_opts * opts , unsigned int flags ,
1729
1725
struct object_id * oid )
1730
1726
{
@@ -1740,7 +1736,7 @@ static int do_commit(struct repository *r,
1740
1736
msg_file );
1741
1737
1742
1738
res = try_to_commit (r , msg_file ? & sb : NULL ,
1743
- author , opts , flags , & oid );
1739
+ author , reflog_action , opts , flags , & oid );
1744
1740
strbuf_release (& sb );
1745
1741
if (!res ) {
1746
1742
refs_delete_ref (get_main_ref_store (r ), "" ,
@@ -1756,7 +1752,7 @@ static int do_commit(struct repository *r,
1756
1752
if (is_rebase_i (opts ) && oid )
1757
1753
if (write_rebase_head (oid ))
1758
1754
return -1 ;
1759
- return run_git_commit (msg_file , opts , flags );
1755
+ return run_git_commit (msg_file , reflog_action , opts , flags );
1760
1756
}
1761
1757
1762
1758
return res ;
@@ -2226,6 +2222,39 @@ static void refer_to_commit(struct replay_opts *opts,
2226
2222
}
2227
2223
}
2228
2224
2225
+ static const char * sequencer_reflog_action (struct replay_opts * opts )
2226
+ {
2227
+ if (!opts -> reflog_action ) {
2228
+ opts -> reflog_action = getenv (GIT_REFLOG_ACTION );
2229
+ opts -> reflog_action =
2230
+ xstrdup (opts -> reflog_action ? opts -> reflog_action
2231
+ : action_name (opts ));
2232
+ }
2233
+
2234
+ return opts -> reflog_action ;
2235
+ }
2236
+
2237
+ __attribute__((format (printf , 3 , 4 )))
2238
+ static const char * reflog_message (struct replay_opts * opts ,
2239
+ const char * sub_action , const char * fmt , ...)
2240
+ {
2241
+ va_list ap ;
2242
+ static struct strbuf buf = STRBUF_INIT ;
2243
+
2244
+ va_start (ap , fmt );
2245
+ strbuf_reset (& buf );
2246
+ strbuf_addstr (& buf , sequencer_reflog_action (opts ));
2247
+ if (sub_action )
2248
+ strbuf_addf (& buf , " (%s)" , sub_action );
2249
+ if (fmt ) {
2250
+ strbuf_addstr (& buf , ": " );
2251
+ strbuf_vaddf (& buf , fmt , ap );
2252
+ }
2253
+ va_end (ap );
2254
+
2255
+ return buf .buf ;
2256
+ }
2257
+
2229
2258
static int do_pick_commit (struct repository * r ,
2230
2259
struct todo_item * item ,
2231
2260
struct replay_opts * opts ,
@@ -2236,13 +2265,19 @@ static int do_pick_commit(struct repository *r,
2236
2265
const char * msg_file = should_edit (opts ) ? NULL : git_path_merge_msg (r );
2237
2266
struct object_id head ;
2238
2267
struct commit * base , * next , * parent ;
2239
- const char * base_label , * next_label ;
2268
+ const char * base_label , * next_label , * reflog_action ;
2240
2269
char * author = NULL ;
2241
2270
struct commit_message msg = { NULL , NULL , NULL , NULL };
2242
2271
int res , unborn = 0 , reword = 0 , allow , drop_commit ;
2243
2272
enum todo_command command = item -> command ;
2244
2273
struct commit * commit = item -> commit ;
2245
2274
2275
+ if (is_rebase_i (opts ))
2276
+ reflog_action = reflog_message (
2277
+ opts , command_to_string (item -> command ), NULL );
2278
+ else
2279
+ reflog_action = sequencer_reflog_action (opts );
2280
+
2246
2281
if (opts -> no_commit ) {
2247
2282
/*
2248
2283
* We do not intend to commit immediately. We just want to
@@ -2494,7 +2529,8 @@ static int do_pick_commit(struct repository *r,
2494
2529
} /* else allow == 0 and there's nothing special to do */
2495
2530
if (!opts -> no_commit && !drop_commit ) {
2496
2531
if (author || command == TODO_REVERT || (flags & AMEND_MSG ))
2497
- res = do_commit (r , msg_file , author , opts , flags ,
2532
+ res = do_commit (r , msg_file , author , reflog_action ,
2533
+ opts , flags ,
2498
2534
commit ? & commit -> object .oid : NULL );
2499
2535
else
2500
2536
res = error (_ ("unable to parse commit author" ));
@@ -2509,7 +2545,7 @@ static int do_pick_commit(struct repository *r,
2509
2545
* got here.
2510
2546
*/
2511
2547
flags = EDIT_MSG | VERIFY_MSG | AMEND_MSG | ALLOW_EMPTY ;
2512
- res = run_git_commit (NULL , opts , flags );
2548
+ res = run_git_commit (NULL , reflog_action , opts , flags );
2513
2549
* check_todo = 1 ;
2514
2550
}
2515
2551
}
@@ -3919,39 +3955,6 @@ static int do_label(struct repository *r, const char *name, int len)
3919
3955
return ret ;
3920
3956
}
3921
3957
3922
- static const char * sequencer_reflog_action (struct replay_opts * opts )
3923
- {
3924
- if (!opts -> reflog_action ) {
3925
- opts -> reflog_action = getenv (GIT_REFLOG_ACTION );
3926
- opts -> reflog_action =
3927
- xstrdup (opts -> reflog_action ? opts -> reflog_action
3928
- : action_name (opts ));
3929
- }
3930
-
3931
- return opts -> reflog_action ;
3932
- }
3933
-
3934
- __attribute__((format (printf , 3 , 4 )))
3935
- static const char * reflog_message (struct replay_opts * opts ,
3936
- const char * sub_action , const char * fmt , ...)
3937
- {
3938
- va_list ap ;
3939
- static struct strbuf buf = STRBUF_INIT ;
3940
-
3941
- va_start (ap , fmt );
3942
- strbuf_reset (& buf );
3943
- strbuf_addstr (& buf , sequencer_reflog_action (opts ));
3944
- if (sub_action )
3945
- strbuf_addf (& buf , " (%s)" , sub_action );
3946
- if (fmt ) {
3947
- strbuf_addstr (& buf , ": " );
3948
- strbuf_vaddf (& buf , fmt , ap );
3949
- }
3950
- va_end (ap );
3951
-
3952
- return buf .buf ;
3953
- }
3954
-
3955
3958
static struct commit * lookup_label (struct repository * r , const char * label ,
3956
3959
int len , struct strbuf * buf )
3957
3960
{
@@ -4089,6 +4092,7 @@ static int do_merge(struct repository *r,
4089
4092
int merge_arg_len , oneline_offset , can_fast_forward , ret , k ;
4090
4093
static struct lock_file lock ;
4091
4094
const char * p ;
4095
+ const char * reflog_action = reflog_message (opts , "merge" , NULL );
4092
4096
4093
4097
if (repo_hold_locked_index (r , & lock , LOCK_REPORT_ON_ERROR ) < 0 ) {
4094
4098
ret = -1 ;
@@ -4360,14 +4364,15 @@ static int do_merge(struct repository *r,
4360
4364
* value (a negative one would indicate that the `merge`
4361
4365
* command needs to be rescheduled).
4362
4366
*/
4363
- ret = !!run_git_commit (git_path_merge_msg (r ), opts ,
4364
- run_commit_flags );
4367
+ ret = !!run_git_commit (git_path_merge_msg (r ), reflog_action ,
4368
+ opts , run_commit_flags );
4365
4369
4366
4370
if (!ret && flags & TODO_EDIT_MERGE_MSG ) {
4367
4371
fast_forward_edit :
4368
4372
* check_todo = 1 ;
4369
4373
run_commit_flags |= AMEND_MSG | EDIT_MSG | VERIFY_MSG ;
4370
- ret = !!run_git_commit (NULL , opts , run_commit_flags );
4374
+ ret = !!run_git_commit (NULL , reflog_action , opts ,
4375
+ run_commit_flags );
4371
4376
}
4372
4377
4373
4378
@@ -4882,13 +4887,9 @@ static int pick_one_commit(struct repository *r,
4882
4887
struct replay_opts * opts ,
4883
4888
int * check_todo , int * reschedule )
4884
4889
{
4885
- struct replay_ctx * ctx = opts -> ctx ;
4886
4890
int res ;
4887
4891
struct todo_item * item = todo_list -> items + todo_list -> current ;
4888
4892
const char * arg = todo_item_get_arg (todo_list , item );
4889
- if (is_rebase_i (opts ))
4890
- ctx -> reflog_message = reflog_message (
4891
- opts , command_to_string (item -> command ), NULL );
4892
4893
4893
4894
res = do_pick_commit (r , item , opts , is_final_fixup (todo_list ),
4894
4895
check_todo );
@@ -4947,7 +4948,6 @@ static int pick_commits(struct repository *r,
4947
4948
struct replay_ctx * ctx = opts -> ctx ;
4948
4949
int res = 0 , reschedule = 0 ;
4949
4950
4950
- ctx -> reflog_message = sequencer_reflog_action (opts );
4951
4951
if (opts -> allow_ff )
4952
4952
ASSERT (!(opts -> signoff || opts -> no_commit ||
4953
4953
opts -> record_origin || should_edit (opts ) ||
@@ -5208,6 +5208,7 @@ static int commit_staged_changes(struct repository *r,
5208
5208
unsigned int flags = ALLOW_EMPTY | EDIT_MSG ;
5209
5209
unsigned int final_fixup = 0 , is_clean ;
5210
5210
struct strbuf rev = STRBUF_INIT ;
5211
+ const char * reflog_action = reflog_message (opts , "continue" , NULL );
5211
5212
int ret ;
5212
5213
5213
5214
if (has_unstaged_changes (r , 1 )) {
@@ -5370,7 +5371,7 @@ static int commit_staged_changes(struct repository *r,
5370
5371
}
5371
5372
5372
5373
if (run_git_commit (final_fixup ? NULL : rebase_path_message (),
5373
- opts , flags )) {
5374
+ reflog_action , opts , flags )) {
5374
5375
ret = error (_ ("could not commit staged changes." ));
5375
5376
goto out ;
5376
5377
}
@@ -5402,7 +5403,6 @@ static int commit_staged_changes(struct repository *r,
5402
5403
5403
5404
int sequencer_continue (struct repository * r , struct replay_opts * opts )
5404
5405
{
5405
- struct replay_ctx * ctx = opts -> ctx ;
5406
5406
struct todo_list todo_list = TODO_LIST_INIT ;
5407
5407
int res ;
5408
5408
@@ -5423,7 +5423,6 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
5423
5423
unlink (rebase_path_dropped ());
5424
5424
}
5425
5425
5426
- ctx -> reflog_message = reflog_message (opts , "continue" , NULL );
5427
5426
if (commit_staged_changes (r , opts , & todo_list )) {
5428
5427
res = -1 ;
5429
5428
goto release_todo_list ;
@@ -5475,7 +5474,6 @@ static int single_pick(struct repository *r,
5475
5474
TODO_PICK : TODO_REVERT ;
5476
5475
item .commit = cmit ;
5477
5476
5478
- opts -> ctx -> reflog_message = sequencer_reflog_action (opts );
5479
5477
return do_pick_commit (r , & item , opts , 0 , & check_todo );
5480
5478
}
5481
5479
0 commit comments