rebase: cleanup action handling
Treating the action as a string is a hang over from the scripted rebase. The last commit removed the only remaining use of the action that required a string so lets convert the other action users to use the existing action enum instead. If we ever need the action name as a string in the future the action_names array exists exactly for that purpose. 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
6159e7add4
commit
9a1925b08f
@ -59,6 +59,26 @@ enum empty_type {
|
|||||||
EMPTY_ASK
|
EMPTY_ASK
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum action {
|
||||||
|
ACTION_NONE = 0,
|
||||||
|
ACTION_CONTINUE,
|
||||||
|
ACTION_SKIP,
|
||||||
|
ACTION_ABORT,
|
||||||
|
ACTION_QUIT,
|
||||||
|
ACTION_EDIT_TODO,
|
||||||
|
ACTION_SHOW_CURRENT_PATCH
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *action_names[] = {
|
||||||
|
"undefined",
|
||||||
|
"continue",
|
||||||
|
"skip",
|
||||||
|
"abort",
|
||||||
|
"quit",
|
||||||
|
"edit_todo",
|
||||||
|
"show_current_patch"
|
||||||
|
};
|
||||||
|
|
||||||
struct rebase_options {
|
struct rebase_options {
|
||||||
enum rebase_type type;
|
enum rebase_type type;
|
||||||
enum empty_type empty;
|
enum empty_type empty;
|
||||||
@ -85,7 +105,7 @@ struct rebase_options {
|
|||||||
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
|
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
|
||||||
} flags;
|
} flags;
|
||||||
struct strvec git_am_opts;
|
struct strvec git_am_opts;
|
||||||
const char *action;
|
enum action action;
|
||||||
int signoff;
|
int signoff;
|
||||||
int allow_rerere_autoupdate;
|
int allow_rerere_autoupdate;
|
||||||
int keep_empty;
|
int keep_empty;
|
||||||
@ -156,24 +176,6 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
|
|||||||
return replay;
|
return replay;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum action {
|
|
||||||
ACTION_NONE = 0,
|
|
||||||
ACTION_CONTINUE,
|
|
||||||
ACTION_SKIP,
|
|
||||||
ACTION_ABORT,
|
|
||||||
ACTION_QUIT,
|
|
||||||
ACTION_EDIT_TODO,
|
|
||||||
ACTION_SHOW_CURRENT_PATCH
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *action_names[] = { "undefined",
|
|
||||||
"continue",
|
|
||||||
"skip",
|
|
||||||
"abort",
|
|
||||||
"quit",
|
|
||||||
"edit_todo",
|
|
||||||
"show_current_patch" };
|
|
||||||
|
|
||||||
static int edit_todo_file(unsigned flags)
|
static int edit_todo_file(unsigned flags)
|
||||||
{
|
{
|
||||||
const char *todo_file = rebase_path_todo();
|
const char *todo_file = rebase_path_todo();
|
||||||
@ -310,8 +312,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_sequencer_rebase(struct rebase_options *opts,
|
static int run_sequencer_rebase(struct rebase_options *opts)
|
||||||
enum action command)
|
|
||||||
{
|
{
|
||||||
unsigned flags = 0;
|
unsigned flags = 0;
|
||||||
int abbreviate_commands = 0, ret = 0;
|
int abbreviate_commands = 0, ret = 0;
|
||||||
@ -326,7 +327,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
|
|||||||
flags |= opts->reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0;
|
flags |= opts->reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0;
|
||||||
flags |= opts->flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0;
|
flags |= opts->flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0;
|
||||||
|
|
||||||
switch (command) {
|
switch (opts->action) {
|
||||||
case ACTION_NONE: {
|
case ACTION_NONE: {
|
||||||
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"));
|
||||||
@ -359,7 +360,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BUG("invalid command '%d'", command);
|
BUG("invalid command '%d'", opts->action);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -617,7 +618,7 @@ static int run_am(struct rebase_options *opts)
|
|||||||
strvec_push(&am.args, "am");
|
strvec_push(&am.args, "am");
|
||||||
strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
|
strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
|
||||||
getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
|
getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
|
||||||
if (opts->action && !strcmp("continue", opts->action)) {
|
if (opts->action == ACTION_CONTINUE) {
|
||||||
strvec_push(&am.args, "--resolved");
|
strvec_push(&am.args, "--resolved");
|
||||||
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
|
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
|
||||||
if (opts->gpg_sign_opt)
|
if (opts->gpg_sign_opt)
|
||||||
@ -628,7 +629,7 @@ static int run_am(struct rebase_options *opts)
|
|||||||
|
|
||||||
return move_to_original_branch(opts);
|
return move_to_original_branch(opts);
|
||||||
}
|
}
|
||||||
if (opts->action && !strcmp("skip", opts->action)) {
|
if (opts->action == ACTION_SKIP) {
|
||||||
strvec_push(&am.args, "--skip");
|
strvec_push(&am.args, "--skip");
|
||||||
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
|
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
|
||||||
status = run_command(&am);
|
status = run_command(&am);
|
||||||
@ -637,7 +638,7 @@ static int run_am(struct rebase_options *opts)
|
|||||||
|
|
||||||
return move_to_original_branch(opts);
|
return move_to_original_branch(opts);
|
||||||
}
|
}
|
||||||
if (opts->action && !strcmp("show-current-patch", opts->action)) {
|
if (opts->action == ACTION_SHOW_CURRENT_PATCH) {
|
||||||
strvec_push(&am.args, "--show-current-patch");
|
strvec_push(&am.args, "--show-current-patch");
|
||||||
return run_command(&am);
|
return run_command(&am);
|
||||||
}
|
}
|
||||||
@ -730,7 +731,7 @@ static int run_am(struct rebase_options *opts)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_specific_rebase(struct rebase_options *opts, enum action action)
|
static int run_specific_rebase(struct rebase_options *opts)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -748,7 +749,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action)
|
|||||||
opts->gpg_sign_opt = tmp;
|
opts->gpg_sign_opt = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = run_sequencer_rebase(opts, action);
|
status = run_sequencer_rebase(opts);
|
||||||
} else if (opts->type == REBASE_APPLY)
|
} else if (opts->type == REBASE_APPLY)
|
||||||
status = run_am(opts);
|
status = run_am(opts);
|
||||||
else
|
else
|
||||||
@ -1025,7 +1026,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct object_id branch_base;
|
struct object_id branch_base;
|
||||||
int ignore_whitespace = 0;
|
int ignore_whitespace = 0;
|
||||||
enum action action = ACTION_NONE;
|
|
||||||
const char *gpg_sign = NULL;
|
const char *gpg_sign = NULL;
|
||||||
struct string_list exec = STRING_LIST_INIT_NODUP;
|
struct string_list exec = STRING_LIST_INIT_NODUP;
|
||||||
const char *rebase_merges = NULL;
|
const char *rebase_merges = NULL;
|
||||||
@ -1074,18 +1074,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_BIT(0, "no-ff", &options.flags,
|
OPT_BIT(0, "no-ff", &options.flags,
|
||||||
N_("cherry-pick all commits, even if unchanged"),
|
N_("cherry-pick all commits, even if unchanged"),
|
||||||
REBASE_FORCE),
|
REBASE_FORCE),
|
||||||
OPT_CMDMODE(0, "continue", &action, N_("continue"),
|
OPT_CMDMODE(0, "continue", &options.action, N_("continue"),
|
||||||
ACTION_CONTINUE),
|
ACTION_CONTINUE),
|
||||||
OPT_CMDMODE(0, "skip", &action,
|
OPT_CMDMODE(0, "skip", &options.action,
|
||||||
N_("skip current patch and continue"), ACTION_SKIP),
|
N_("skip current patch and continue"), ACTION_SKIP),
|
||||||
OPT_CMDMODE(0, "abort", &action,
|
OPT_CMDMODE(0, "abort", &options.action,
|
||||||
N_("abort and check out the original branch"),
|
N_("abort and check out the original branch"),
|
||||||
ACTION_ABORT),
|
ACTION_ABORT),
|
||||||
OPT_CMDMODE(0, "quit", &action,
|
OPT_CMDMODE(0, "quit", &options.action,
|
||||||
N_("abort but keep HEAD where it is"), ACTION_QUIT),
|
N_("abort but keep HEAD where it is"), ACTION_QUIT),
|
||||||
OPT_CMDMODE(0, "edit-todo", &action, N_("edit the todo list "
|
OPT_CMDMODE(0, "edit-todo", &options.action, N_("edit the todo list "
|
||||||
"during an interactive rebase"), ACTION_EDIT_TODO),
|
"during an interactive rebase"), ACTION_EDIT_TODO),
|
||||||
OPT_CMDMODE(0, "show-current-patch", &action,
|
OPT_CMDMODE(0, "show-current-patch", &options.action,
|
||||||
N_("show the patch file being applied or merged"),
|
N_("show the patch file being applied or merged"),
|
||||||
ACTION_SHOW_CURRENT_PATCH),
|
ACTION_SHOW_CURRENT_PATCH),
|
||||||
OPT_CALLBACK_F(0, "apply", &options, NULL,
|
OPT_CALLBACK_F(0, "apply", &options, NULL,
|
||||||
@ -1174,7 +1174,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
} else if (is_directory(merge_dir())) {
|
} else if (is_directory(merge_dir())) {
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
strbuf_addf(&buf, "%s/rewritten", merge_dir());
|
strbuf_addf(&buf, "%s/rewritten", merge_dir());
|
||||||
if (!(action == ACTION_ABORT) && is_directory(buf.buf)) {
|
if (!(options.action == ACTION_ABORT) && is_directory(buf.buf)) {
|
||||||
die(_("`rebase --preserve-merges` (-p) is no longer supported.\n"
|
die(_("`rebase --preserve-merges` (-p) is no longer supported.\n"
|
||||||
"Use `git rebase --abort` to terminate current rebase.\n"
|
"Use `git rebase --abort` to terminate current rebase.\n"
|
||||||
"Or downgrade to v2.33, or earlier, to complete the rebase."));
|
"Or downgrade to v2.33, or earlier, to complete the rebase."));
|
||||||
@ -1201,7 +1201,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
"Note: Your `pull.rebase` configuration may also be set to 'preserve',\n"
|
"Note: Your `pull.rebase` configuration may also be set to 'preserve',\n"
|
||||||
"which is no longer supported; use 'merges' instead"));
|
"which is no longer supported; use 'merges' instead"));
|
||||||
|
|
||||||
if (action != ACTION_NONE && total_argc != 2) {
|
if (options.action != ACTION_NONE && total_argc != 2) {
|
||||||
usage_with_options(builtin_rebase_usage,
|
usage_with_options(builtin_rebase_usage,
|
||||||
builtin_rebase_options);
|
builtin_rebase_options);
|
||||||
}
|
}
|
||||||
@ -1232,11 +1232,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
if (options.root && options.fork_point > 0)
|
if (options.root && options.fork_point > 0)
|
||||||
die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point");
|
die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point");
|
||||||
|
|
||||||
if (action != ACTION_NONE && !in_progress)
|
if (options.action != ACTION_NONE && !in_progress)
|
||||||
die(_("No rebase in progress?"));
|
die(_("No rebase in progress?"));
|
||||||
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
|
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
|
||||||
|
|
||||||
if (action == ACTION_EDIT_TODO && !is_merge(&options))
|
if (options.action == ACTION_EDIT_TODO && !is_merge(&options))
|
||||||
die(_("The --edit-todo action can only be used during "
|
die(_("The --edit-todo action can only be used during "
|
||||||
"interactive rebase."));
|
"interactive rebase."));
|
||||||
|
|
||||||
@ -1246,16 +1246,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
else if (exec.nr)
|
else if (exec.nr)
|
||||||
trace2_cmd_mode("interactive-exec");
|
trace2_cmd_mode("interactive-exec");
|
||||||
else
|
else
|
||||||
trace2_cmd_mode(action_names[action]);
|
trace2_cmd_mode(action_names[options.action]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action) {
|
switch (options.action) {
|
||||||
case ACTION_CONTINUE: {
|
case ACTION_CONTINUE: {
|
||||||
struct object_id head;
|
struct object_id head;
|
||||||
struct lock_file lock_file = LOCK_INIT;
|
struct lock_file lock_file = LOCK_INIT;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
options.action = "continue";
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (get_oid("HEAD", &head))
|
if (get_oid("HEAD", &head))
|
||||||
die(_("Cannot read HEAD"));
|
die(_("Cannot read HEAD"));
|
||||||
@ -1281,7 +1280,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
case ACTION_SKIP: {
|
case ACTION_SKIP: {
|
||||||
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
||||||
|
|
||||||
options.action = "skip";
|
|
||||||
rerere_clear(the_repository, &merge_rr);
|
rerere_clear(the_repository, &merge_rr);
|
||||||
string_list_clear(&merge_rr, 1);
|
string_list_clear(&merge_rr, 1);
|
||||||
ropts.flags = RESET_HEAD_HARD;
|
ropts.flags = RESET_HEAD_HARD;
|
||||||
@ -1296,7 +1294,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
||||||
struct strbuf head_msg = STRBUF_INIT;
|
struct strbuf head_msg = STRBUF_INIT;
|
||||||
|
|
||||||
options.action = "abort";
|
|
||||||
rerere_clear(the_repository, &merge_rr);
|
rerere_clear(the_repository, &merge_rr);
|
||||||
string_list_clear(&merge_rr, 1);
|
string_list_clear(&merge_rr, 1);
|
||||||
|
|
||||||
@ -1336,17 +1333,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
case ACTION_EDIT_TODO:
|
case ACTION_EDIT_TODO:
|
||||||
options.action = "edit-todo";
|
|
||||||
options.dont_finish_rebase = 1;
|
options.dont_finish_rebase = 1;
|
||||||
goto run_rebase;
|
goto run_rebase;
|
||||||
case ACTION_SHOW_CURRENT_PATCH:
|
case ACTION_SHOW_CURRENT_PATCH:
|
||||||
options.action = "show-current-patch";
|
|
||||||
options.dont_finish_rebase = 1;
|
options.dont_finish_rebase = 1;
|
||||||
goto run_rebase;
|
goto run_rebase;
|
||||||
case ACTION_NONE:
|
case ACTION_NONE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BUG("action: %d", action);
|
BUG("action: %d", options.action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure no rebase is in progress */
|
/* Make sure no rebase is in progress */
|
||||||
@ -1370,7 +1365,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
|
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
|
||||||
(action != ACTION_NONE) ||
|
(options.action != ACTION_NONE) ||
|
||||||
(exec.nr > 0) ||
|
(exec.nr > 0) ||
|
||||||
options.autosquash) {
|
options.autosquash) {
|
||||||
allow_preemptive_ff = 0;
|
allow_preemptive_ff = 0;
|
||||||
@ -1815,7 +1810,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
options.revisions = revisions.buf;
|
options.revisions = revisions.buf;
|
||||||
|
|
||||||
run_rebase:
|
run_rebase:
|
||||||
ret = run_specific_rebase(&options, action);
|
ret = run_specific_rebase(&options);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
|
Reference in New Issue
Block a user