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 <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
73fdc535d2
commit
0ea0847ef0
@ -113,6 +113,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
|
|||||||
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
|
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
|
||||||
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
|
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
|
||||||
replay.strategy = opts->strategy;
|
replay.strategy = opts->strategy;
|
||||||
|
if (opts->strategy_opts)
|
||||||
|
parse_strategy_opts(&replay, opts->strategy_opts);
|
||||||
|
|
||||||
return replay;
|
return replay;
|
||||||
}
|
}
|
||||||
@ -262,44 +264,50 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
|
|||||||
return write_basic_state(opts, head_name, onto, orig_head);
|
return write_basic_state(opts, head_name, onto, orig_head);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
|
static void split_exec_commands(const char *cmd, struct string_list *commands)
|
||||||
const char *switch_to, struct commit *upstream,
|
{
|
||||||
struct commit *onto, const char *onto_name,
|
if (cmd && *cmd) {
|
||||||
struct object_id *squash_onto, const char *head_name,
|
string_list_split(commands, cmd, '\n', -1);
|
||||||
struct commit *restrict_revision, char *raw_strategies,
|
|
||||||
struct string_list *commands, unsigned autosquash)
|
/* rebase.c adds a new line to cmd after every command,
|
||||||
|
* so here the last command is always empty */
|
||||||
|
string_list_remove_empty_items(commands, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
const char *head_hash = NULL;
|
const char *head_hash = NULL;
|
||||||
char *revisions = NULL, *shortrevisions = NULL;
|
char *revisions = NULL, *shortrevisions = NULL;
|
||||||
struct argv_array make_script_args = ARGV_ARRAY_INIT;
|
struct argv_array make_script_args = ARGV_ARRAY_INIT;
|
||||||
struct todo_list todo_list = TODO_LIST_INIT;
|
struct todo_list todo_list = TODO_LIST_INIT;
|
||||||
|
struct replay_opts replay = get_replay_opts(opts);
|
||||||
|
struct string_list commands = STRING_LIST_INIT_DUP;
|
||||||
|
|
||||||
if (prepare_branch_to_be_rebased(the_repository, opts, switch_to))
|
if (prepare_branch_to_be_rebased(the_repository, &replay,
|
||||||
|
opts->switch_to))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (get_revision_ranges(upstream, onto, &head_hash,
|
if (get_revision_ranges(opts->upstream, opts->onto, &head_hash,
|
||||||
&revisions, &shortrevisions))
|
&revisions, &shortrevisions))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (raw_strategies)
|
if (init_basic_state(&replay, opts->head_name, opts->onto, head_hash)) {
|
||||||
parse_strategy_opts(opts, raw_strategies);
|
|
||||||
|
|
||||||
if (init_basic_state(opts, head_name, onto, head_hash)) {
|
|
||||||
free(revisions);
|
free(revisions);
|
||||||
free(shortrevisions);
|
free(shortrevisions);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!upstream && squash_onto)
|
if (!opts->upstream && opts->squash_onto)
|
||||||
write_file(path_squash_onto(), "%s\n",
|
write_file(path_squash_onto(), "%s\n",
|
||||||
oid_to_hex(squash_onto));
|
oid_to_hex(opts->squash_onto));
|
||||||
|
|
||||||
argv_array_pushl(&make_script_args, "", revisions, NULL);
|
argv_array_pushl(&make_script_args, "", revisions, NULL);
|
||||||
if (restrict_revision)
|
if (opts->restrict_revision)
|
||||||
argv_array_push(&make_script_args,
|
argv_array_push(&make_script_args,
|
||||||
oid_to_hex(&restrict_revision->object.oid));
|
oid_to_hex(&opts->restrict_revision->object.oid));
|
||||||
|
|
||||||
ret = sequencer_make_script(the_repository, &todo_list.buf,
|
ret = sequencer_make_script(the_repository, &todo_list.buf,
|
||||||
make_script_args.argc, make_script_args.argv,
|
make_script_args.argc, make_script_args.argv,
|
||||||
@ -313,10 +321,13 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
|
|||||||
&todo_list))
|
&todo_list))
|
||||||
BUG("unusable todo list");
|
BUG("unusable todo list");
|
||||||
|
|
||||||
ret = complete_action(the_repository, opts, flags, shortrevisions, onto_name,
|
split_exec_commands(opts->cmd, &commands);
|
||||||
onto, head_hash, commands, autosquash, &todo_list);
|
ret = complete_action(the_repository, &replay, flags,
|
||||||
|
shortrevisions, opts->onto_name, opts->onto, head_hash,
|
||||||
|
&commands, opts->autosquash, &todo_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string_list_clear(&commands, 0);
|
||||||
free(revisions);
|
free(revisions);
|
||||||
free(shortrevisions);
|
free(shortrevisions);
|
||||||
todo_list_release(&todo_list);
|
todo_list_release(&todo_list);
|
||||||
@ -336,7 +347,6 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
|
|||||||
unsigned flags = 0;
|
unsigned flags = 0;
|
||||||
int abbreviate_commands = 0, ret = 0;
|
int abbreviate_commands = 0, ret = 0;
|
||||||
struct object_id squash_onto = null_oid;
|
struct object_id squash_onto = null_oid;
|
||||||
struct string_list commands = STRING_LIST_INIT_DUP;
|
|
||||||
enum {
|
enum {
|
||||||
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH,
|
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH,
|
||||||
SHORTEN_OIDS, EXPAND_OIDS, CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC
|
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)
|
|||||||
warning(_("--[no-]rebase-cousins has no effect without "
|
warning(_("--[no-]rebase-cousins has no effect without "
|
||||||
"--rebase-merges"));
|
"--rebase-merges"));
|
||||||
|
|
||||||
if (opts.cmd && *opts.cmd) {
|
|
||||||
string_list_split(&commands, opts.cmd, '\n', -1);
|
|
||||||
|
|
||||||
/* rebase.c adds a new line to cmd after every command,
|
|
||||||
* so here the last command is always empty */
|
|
||||||
string_list_remove_empty_items(&commands, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case NONE: {
|
case NONE: {
|
||||||
struct replay_opts replay_opts = get_replay_opts(&opts);
|
|
||||||
if (!opts.onto && !opts.upstream)
|
if (!opts.onto && !opts.upstream)
|
||||||
die(_("a base commit must be provided with --upstream or --onto"));
|
die(_("a base commit must be provided with --upstream or --onto"));
|
||||||
|
|
||||||
ret = do_interactive_rebase(&replay_opts, flags, opts.switch_to, opts.upstream, opts.onto,
|
ret = do_interactive_rebase(&opts, flags);
|
||||||
opts.onto_name, opts.squash_onto, opts.head_name, opts.restrict_revision,
|
|
||||||
opts.strategy_opts, &commands, opts.autosquash);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SKIP: {
|
case SKIP: {
|
||||||
@ -477,14 +476,18 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
|
|||||||
case REARRANGE_SQUASH:
|
case REARRANGE_SQUASH:
|
||||||
ret = rearrange_squash_in_todo_file();
|
ret = rearrange_squash_in_todo_file();
|
||||||
break;
|
break;
|
||||||
case ADD_EXEC:
|
case ADD_EXEC: {
|
||||||
|
struct string_list commands = STRING_LIST_INIT_DUP;
|
||||||
|
|
||||||
|
split_exec_commands(opts.cmd, &commands);
|
||||||
ret = add_exec_commands(&commands);
|
ret = add_exec_commands(&commands);
|
||||||
|
string_list_clear(&commands, 0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
BUG("invalid command '%d'", command);
|
BUG("invalid command '%d'", command);
|
||||||
}
|
}
|
||||||
|
|
||||||
string_list_clear(&commands, 0);
|
|
||||||
return !!ret;
|
return !!ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user