@@ -113,6 +113,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
113
113
replay .reschedule_failed_exec = opts -> reschedule_failed_exec ;
114
114
replay .gpg_sign = xstrdup_or_null (opts -> gpg_sign_opt );
115
115
replay .strategy = opts -> strategy ;
116
+ if (opts -> strategy_opts )
117
+ parse_strategy_opts (& replay , opts -> strategy_opts );
116
118
117
119
return replay ;
118
120
}
@@ -262,44 +264,50 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
262
264
return write_basic_state (opts , head_name , onto , orig_head );
263
265
}
264
266
265
- static int do_interactive_rebase (struct replay_opts * opts , unsigned flags ,
266
- const char * switch_to , struct commit * upstream ,
267
- struct commit * onto , const char * onto_name ,
268
- struct object_id * squash_onto , const char * head_name ,
269
- struct commit * restrict_revision , char * raw_strategies ,
270
- struct string_list * commands , unsigned autosquash )
267
+ static void split_exec_commands (const char * cmd , struct string_list * commands )
268
+ {
269
+ if (cmd && * cmd ) {
270
+ string_list_split (commands , cmd , '\n' , -1 );
271
+
272
+ /* rebase.c adds a new line to cmd after every command,
273
+ * so here the last command is always empty */
274
+ string_list_remove_empty_items (commands , 0 );
275
+ }
276
+ }
277
+
278
+ static int do_interactive_rebase (struct rebase_options * opts , unsigned flags )
271
279
{
272
280
int ret ;
273
281
const char * head_hash = NULL ;
274
282
char * revisions = NULL , * shortrevisions = NULL ;
275
283
struct argv_array make_script_args = ARGV_ARRAY_INIT ;
276
284
struct todo_list todo_list = TODO_LIST_INIT ;
285
+ struct replay_opts replay = get_replay_opts (opts );
286
+ struct string_list commands = STRING_LIST_INIT_DUP ;
277
287
278
- if (prepare_branch_to_be_rebased (the_repository , opts , switch_to ))
288
+ if (prepare_branch_to_be_rebased (the_repository , & replay ,
289
+ opts -> switch_to ))
279
290
return -1 ;
280
291
281
- if (get_revision_ranges (upstream , onto , & head_hash ,
292
+ if (get_revision_ranges (opts -> upstream , opts -> onto , & head_hash ,
282
293
& revisions , & shortrevisions ))
283
294
return -1 ;
284
295
285
- if (raw_strategies )
286
- parse_strategy_opts (opts , raw_strategies );
287
-
288
- if (init_basic_state (opts , head_name , onto , head_hash )) {
296
+ if (init_basic_state (& replay , opts -> head_name , opts -> onto , head_hash )) {
289
297
free (revisions );
290
298
free (shortrevisions );
291
299
292
300
return -1 ;
293
301
}
294
302
295
- if (!upstream && squash_onto )
303
+ if (!opts -> upstream && opts -> squash_onto )
296
304
write_file (path_squash_onto (), "%s\n" ,
297
- oid_to_hex (squash_onto ));
305
+ oid_to_hex (opts -> squash_onto ));
298
306
299
307
argv_array_pushl (& make_script_args , "" , revisions , NULL );
300
- if (restrict_revision )
308
+ if (opts -> restrict_revision )
301
309
argv_array_push (& make_script_args ,
302
- oid_to_hex (& restrict_revision -> object .oid ));
310
+ oid_to_hex (& opts -> restrict_revision -> object .oid ));
303
311
304
312
ret = sequencer_make_script (the_repository , & todo_list .buf ,
305
313
make_script_args .argc , make_script_args .argv ,
@@ -313,10 +321,13 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
313
321
& todo_list ))
314
322
BUG ("unusable todo list" );
315
323
316
- ret = complete_action (the_repository , opts , flags , shortrevisions , onto_name ,
317
- onto , head_hash , commands , autosquash , & todo_list );
324
+ split_exec_commands (opts -> cmd , & commands );
325
+ ret = complete_action (the_repository , & replay , flags ,
326
+ shortrevisions , opts -> onto_name , opts -> onto , head_hash ,
327
+ & commands , opts -> autosquash , & todo_list );
318
328
}
319
329
330
+ string_list_clear (& commands , 0 );
320
331
free (revisions );
321
332
free (shortrevisions );
322
333
todo_list_release (& todo_list );
@@ -336,7 +347,6 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
336
347
unsigned flags = 0 ;
337
348
int abbreviate_commands = 0 , ret = 0 ;
338
349
struct object_id squash_onto = null_oid ;
339
- struct string_list commands = STRING_LIST_INIT_DUP ;
340
350
enum {
341
351
NONE = 0 , CONTINUE , SKIP , EDIT_TODO , SHOW_CURRENT_PATCH ,
342
352
SHORTEN_OIDS , EXPAND_OIDS , CHECK_TODO_LIST , REARRANGE_SQUASH , ADD_EXEC
@@ -424,23 +434,12 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
424
434
warning (_ ("--[no-]rebase-cousins has no effect without "
425
435
"--rebase-merges" ));
426
436
427
- if (opts .cmd && * opts .cmd ) {
428
- string_list_split (& commands , opts .cmd , '\n' , -1 );
429
-
430
- /* rebase.c adds a new line to cmd after every command,
431
- * so here the last command is always empty */
432
- string_list_remove_empty_items (& commands , 0 );
433
- }
434
-
435
437
switch (command ) {
436
438
case NONE : {
437
- struct replay_opts replay_opts = get_replay_opts (& opts );
438
439
if (!opts .onto && !opts .upstream )
439
440
die (_ ("a base commit must be provided with --upstream or --onto" ));
440
441
441
- ret = do_interactive_rebase (& replay_opts , flags , opts .switch_to , opts .upstream , opts .onto ,
442
- opts .onto_name , opts .squash_onto , opts .head_name , opts .restrict_revision ,
443
- opts .strategy_opts , & commands , opts .autosquash );
442
+ ret = do_interactive_rebase (& opts , flags );
444
443
break ;
445
444
}
446
445
case SKIP : {
@@ -477,14 +476,18 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
477
476
case REARRANGE_SQUASH :
478
477
ret = rearrange_squash_in_todo_file ();
479
478
break ;
480
- case ADD_EXEC :
479
+ case ADD_EXEC : {
480
+ struct string_list commands = STRING_LIST_INIT_DUP ;
481
+
482
+ split_exec_commands (opts .cmd , & commands );
481
483
ret = add_exec_commands (& commands );
484
+ string_list_clear (& commands , 0 );
482
485
break ;
486
+ }
483
487
default :
484
488
BUG ("invalid command '%d'" , command );
485
489
}
486
490
487
- string_list_clear (& commands , 0 );
488
491
return !!ret ;
489
492
}
490
493
0 commit comments