Skip to content

Commit 0ea0847

Browse files
phillipwoodgitster
authored andcommitted
rebase -i: use struct rebase_options in do_interactive_rebase()
All the parameters that are passed to do_interactive_rebase() apart from `flags` are already in `struct rebase_options` so there is no need to pass them separately. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73fdc53 commit 0ea0847

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

builtin/rebase.c

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
113113
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
114114
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
115115
replay.strategy = opts->strategy;
116+
if (opts->strategy_opts)
117+
parse_strategy_opts(&replay, opts->strategy_opts);
116118

117119
return replay;
118120
}
@@ -262,44 +264,50 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
262264
return write_basic_state(opts, head_name, onto, orig_head);
263265
}
264266

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)
271279
{
272280
int ret;
273281
const char *head_hash = NULL;
274282
char *revisions = NULL, *shortrevisions = NULL;
275283
struct argv_array make_script_args = ARGV_ARRAY_INIT;
276284
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;
277287

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))
279290
return -1;
280291

281-
if (get_revision_ranges(upstream, onto, &head_hash,
292+
if (get_revision_ranges(opts->upstream, opts->onto, &head_hash,
282293
&revisions, &shortrevisions))
283294
return -1;
284295

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)) {
289297
free(revisions);
290298
free(shortrevisions);
291299

292300
return -1;
293301
}
294302

295-
if (!upstream && squash_onto)
303+
if (!opts->upstream && opts->squash_onto)
296304
write_file(path_squash_onto(), "%s\n",
297-
oid_to_hex(squash_onto));
305+
oid_to_hex(opts->squash_onto));
298306

299307
argv_array_pushl(&make_script_args, "", revisions, NULL);
300-
if (restrict_revision)
308+
if (opts->restrict_revision)
301309
argv_array_push(&make_script_args,
302-
oid_to_hex(&restrict_revision->object.oid));
310+
oid_to_hex(&opts->restrict_revision->object.oid));
303311

304312
ret = sequencer_make_script(the_repository, &todo_list.buf,
305313
make_script_args.argc, make_script_args.argv,
@@ -313,10 +321,13 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
313321
&todo_list))
314322
BUG("unusable todo list");
315323

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);
318328
}
319329

330+
string_list_clear(&commands, 0);
320331
free(revisions);
321332
free(shortrevisions);
322333
todo_list_release(&todo_list);
@@ -336,7 +347,6 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
336347
unsigned flags = 0;
337348
int abbreviate_commands = 0, ret = 0;
338349
struct object_id squash_onto = null_oid;
339-
struct string_list commands = STRING_LIST_INIT_DUP;
340350
enum {
341351
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH,
342352
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)
424434
warning(_("--[no-]rebase-cousins has no effect without "
425435
"--rebase-merges"));
426436

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-
435437
switch (command) {
436438
case NONE: {
437-
struct replay_opts replay_opts = get_replay_opts(&opts);
438439
if (!opts.onto && !opts.upstream)
439440
die(_("a base commit must be provided with --upstream or --onto"));
440441

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);
444443
break;
445444
}
446445
case SKIP: {
@@ -477,14 +476,18 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
477476
case REARRANGE_SQUASH:
478477
ret = rearrange_squash_in_todo_file();
479478
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);
481483
ret = add_exec_commands(&commands);
484+
string_list_clear(&commands, 0);
482485
break;
486+
}
483487
default:
484488
BUG("invalid command '%d'", command);
485489
}
486490

487-
string_list_clear(&commands, 0);
488491
return !!ret;
489492
}
490493

0 commit comments

Comments
 (0)