@@ -211,6 +211,11 @@ static GIT_PATH_FUNC(rebase_path_keep_redundant_commits, "rebase-merge/keep_redu
211
211
* A 'struct replay_ctx' represents the private state of the sequencer.
212
212
*/
213
213
struct replay_ctx {
214
+ /*
215
+ * The commit message that will be used except at the end of a
216
+ * chain of fixup and squash commands.
217
+ */
218
+ struct strbuf message ;
214
219
/*
215
220
* The list of completed fixup and squash commands in the
216
221
* current chain.
@@ -226,13 +231,18 @@ struct replay_ctx {
226
231
* current chain.
227
232
*/
228
233
int current_fixup_count ;
234
+ /*
235
+ * Whether message contains a commit message.
236
+ */
237
+ unsigned have_message :1 ;
229
238
};
230
239
231
240
struct replay_ctx * replay_ctx_new (void )
232
241
{
233
242
struct replay_ctx * ctx = xcalloc (1 , sizeof (* ctx ));
234
243
235
244
strbuf_init (& ctx -> current_fixups , 0 );
245
+ strbuf_init (& ctx -> message , 0 );
236
246
237
247
return ctx ;
238
248
}
@@ -399,6 +409,7 @@ static const char *gpg_sign_opt_quoted(struct replay_opts *opts)
399
409
static void replay_ctx_release (struct replay_ctx * ctx )
400
410
{
401
411
strbuf_release (& ctx -> current_fixups );
412
+ strbuf_release (& ctx -> message );
402
413
}
403
414
404
415
void replay_opts_release (struct replay_opts * opts )
@@ -2205,7 +2216,6 @@ static int do_pick_commit(struct repository *r,
2205
2216
const char * base_label , * next_label ;
2206
2217
char * author = NULL ;
2207
2218
struct commit_message msg = { NULL , NULL , NULL , NULL };
2208
- struct strbuf msgbuf = STRBUF_INIT ;
2209
2219
int res , unborn = 0 , reword = 0 , allow , drop_commit ;
2210
2220
enum todo_command command = item -> command ;
2211
2221
struct commit * commit = item -> commit ;
@@ -2304,7 +2314,7 @@ static int do_pick_commit(struct repository *r,
2304
2314
next = parent ;
2305
2315
next_label = msg .parent_label ;
2306
2316
if (opts -> commit_use_reference ) {
2307
- strbuf_addstr (& msgbuf ,
2317
+ strbuf_addstr (& ctx -> message ,
2308
2318
"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***" );
2309
2319
} else if (skip_prefix (msg .subject , "Revert \"" , & orig_subject ) &&
2310
2320
/*
@@ -2313,21 +2323,21 @@ static int do_pick_commit(struct repository *r,
2313
2323
* thus requiring excessive complexity to deal with.
2314
2324
*/
2315
2325
!starts_with (orig_subject , "Revert \"" )) {
2316
- strbuf_addstr (& msgbuf , "Reapply \"" );
2317
- strbuf_addstr (& msgbuf , orig_subject );
2326
+ strbuf_addstr (& ctx -> message , "Reapply \"" );
2327
+ strbuf_addstr (& ctx -> message , orig_subject );
2318
2328
} else {
2319
- strbuf_addstr (& msgbuf , "Revert \"" );
2320
- strbuf_addstr (& msgbuf , msg .subject );
2321
- strbuf_addstr (& msgbuf , "\"" );
2329
+ strbuf_addstr (& ctx -> message , "Revert \"" );
2330
+ strbuf_addstr (& ctx -> message , msg .subject );
2331
+ strbuf_addstr (& ctx -> message , "\"" );
2322
2332
}
2323
- strbuf_addstr (& msgbuf , "\n\nThis reverts commit " );
2324
- refer_to_commit (opts , & msgbuf , commit );
2333
+ strbuf_addstr (& ctx -> message , "\n\nThis reverts commit " );
2334
+ refer_to_commit (opts , & ctx -> message , commit );
2325
2335
2326
2336
if (commit -> parents && commit -> parents -> next ) {
2327
- strbuf_addstr (& msgbuf , ", reversing\nchanges made to " );
2328
- refer_to_commit (opts , & msgbuf , parent );
2337
+ strbuf_addstr (& ctx -> message , ", reversing\nchanges made to " );
2338
+ refer_to_commit (opts , & ctx -> message , parent );
2329
2339
}
2330
- strbuf_addstr (& msgbuf , ".\n" );
2340
+ strbuf_addstr (& ctx -> message , ".\n" );
2331
2341
} else {
2332
2342
const char * p ;
2333
2343
@@ -2336,21 +2346,22 @@ static int do_pick_commit(struct repository *r,
2336
2346
next = commit ;
2337
2347
next_label = msg .label ;
2338
2348
2339
- /* Append the commit log message to msgbuf . */
2349
+ /* Append the commit log message to ctx->message . */
2340
2350
if (find_commit_subject (msg .message , & p ))
2341
- strbuf_addstr (& msgbuf , p );
2351
+ strbuf_addstr (& ctx -> message , p );
2342
2352
2343
2353
if (opts -> record_origin ) {
2344
- strbuf_complete_line (& msgbuf );
2345
- if (!has_conforming_footer (& msgbuf , NULL , 0 ))
2346
- strbuf_addch (& msgbuf , '\n' );
2347
- strbuf_addstr (& msgbuf , cherry_picked_prefix );
2348
- strbuf_addstr (& msgbuf , oid_to_hex (& commit -> object .oid ));
2349
- strbuf_addstr (& msgbuf , ")\n" );
2354
+ strbuf_complete_line (& ctx -> message );
2355
+ if (!has_conforming_footer (& ctx -> message , NULL , 0 ))
2356
+ strbuf_addch (& ctx -> message , '\n' );
2357
+ strbuf_addstr (& ctx -> message , cherry_picked_prefix );
2358
+ strbuf_addstr (& ctx -> message , oid_to_hex (& commit -> object .oid ));
2359
+ strbuf_addstr (& ctx -> message , ")\n" );
2350
2360
}
2351
2361
if (!is_fixup (command ))
2352
2362
author = get_author (msg .message );
2353
2363
}
2364
+ ctx -> have_message = 1 ;
2354
2365
2355
2366
if (command == TODO_REWORD )
2356
2367
reword = 1 ;
@@ -2381,7 +2392,7 @@ static int do_pick_commit(struct repository *r,
2381
2392
}
2382
2393
2383
2394
if (opts -> signoff && !is_fixup (command ))
2384
- append_signoff (& msgbuf , 0 , 0 );
2395
+ append_signoff (& ctx -> message , 0 , 0 );
2385
2396
2386
2397
if (is_rebase_i (opts ) && write_author_script (msg .message ) < 0 )
2387
2398
res = -1 ;
@@ -2390,17 +2401,17 @@ static int do_pick_commit(struct repository *r,
2390
2401
!strcmp (opts -> strategy , "ort" ) ||
2391
2402
command == TODO_REVERT ) {
2392
2403
res = do_recursive_merge (r , base , next , base_label , next_label ,
2393
- & head , & msgbuf , opts );
2404
+ & head , & ctx -> message , opts );
2394
2405
if (res < 0 )
2395
2406
goto leave ;
2396
2407
2397
- res |= write_message (msgbuf .buf , msgbuf .len ,
2408
+ res |= write_message (ctx -> message .buf , ctx -> message .len ,
2398
2409
git_path_merge_msg (r ), 0 );
2399
2410
} else {
2400
2411
struct commit_list * common = NULL ;
2401
2412
struct commit_list * remotes = NULL ;
2402
2413
2403
- res = write_message (msgbuf .buf , msgbuf .len ,
2414
+ res = write_message (ctx -> message .buf , ctx -> message .len ,
2404
2415
git_path_merge_msg (r ), 0 );
2405
2416
2406
2417
commit_list_insert (base , & common );
@@ -2485,7 +2496,6 @@ static int do_pick_commit(struct repository *r,
2485
2496
leave :
2486
2497
free_message (commit , & msg );
2487
2498
free (author );
2488
- strbuf_release (& msgbuf );
2489
2499
update_abort_safety_file ();
2490
2500
2491
2501
return res ;
@@ -3952,6 +3962,7 @@ static int do_merge(struct repository *r,
3952
3962
const char * arg , int arg_len ,
3953
3963
int flags , int * check_todo , struct replay_opts * opts )
3954
3964
{
3965
+ struct replay_ctx * ctx = opts -> ctx ;
3955
3966
int run_commit_flags = 0 ;
3956
3967
struct strbuf ref_name = STRBUF_INIT ;
3957
3968
struct commit * head_commit , * merge_commit , * i ;
@@ -4080,40 +4091,31 @@ static int do_merge(struct repository *r,
4080
4091
write_author_script (message );
4081
4092
find_commit_subject (message , & body );
4082
4093
len = strlen (body );
4083
- ret = write_message ( body , len , git_path_merge_msg ( r ), 0 );
4094
+ strbuf_add ( & ctx -> message , body , len );
4084
4095
repo_unuse_commit_buffer (r , commit , message );
4085
- if (ret ) {
4086
- error_errno (_ ("could not write '%s'" ),
4087
- git_path_merge_msg (r ));
4088
- goto leave_merge ;
4089
- }
4090
4096
} else {
4091
4097
struct strbuf buf = STRBUF_INIT ;
4092
- int len ;
4093
4098
4094
4099
strbuf_addf (& buf , "author %s" , git_author_info (0 ));
4095
4100
write_author_script (buf .buf );
4096
- strbuf_reset (& buf );
4101
+ strbuf_release (& buf );
4097
4102
4098
4103
if (oneline_offset < arg_len ) {
4099
- p = arg + oneline_offset ;
4100
- len = arg_len - oneline_offset ;
4104
+ strbuf_add ( & ctx -> message , arg + oneline_offset ,
4105
+ arg_len - oneline_offset ) ;
4101
4106
} else {
4102
- strbuf_addf (& buf , "Merge %s '%.*s'" ,
4107
+ strbuf_addf (& ctx -> message , "Merge %s '%.*s'" ,
4103
4108
to_merge -> next ? "branches" : "branch" ,
4104
4109
merge_arg_len , arg );
4105
- p = buf .buf ;
4106
- len = buf .len ;
4107
- }
4108
-
4109
- ret = write_message (p , len , git_path_merge_msg (r ), 0 );
4110
- strbuf_release (& buf );
4111
- if (ret ) {
4112
- error_errno (_ ("could not write '%s'" ),
4113
- git_path_merge_msg (r ));
4114
- goto leave_merge ;
4115
4110
}
4116
4111
}
4112
+ ctx -> have_message = 1 ;
4113
+ if (write_message (ctx -> message .buf , ctx -> message .len ,
4114
+ git_path_merge_msg (r ), 0 )) {
4115
+ ret = error_errno (_ ("could not write '%s'" ),
4116
+ git_path_merge_msg (r ));
4117
+ goto leave_merge ;
4118
+ }
4117
4119
4118
4120
if (strategy || to_merge -> next ) {
4119
4121
/* Octopus merge */
@@ -4885,6 +4887,8 @@ static int pick_commits(struct repository *r,
4885
4887
return stopped_at_head (r );
4886
4888
}
4887
4889
}
4890
+ strbuf_reset (& ctx -> message );
4891
+ ctx -> have_message = 0 ;
4888
4892
if (item -> command <= TODO_SQUASH ) {
4889
4893
res = pick_one_commit (r , todo_list , opts , & check_todo ,
4890
4894
& reschedule );
0 commit comments