Skip to content

Commit 9a1925b

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6159e7a commit 9a1925b

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

builtin/rebase.c

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ enum empty_type {
5959
EMPTY_ASK
6060
};
6161

62+
enum action {
63+
ACTION_NONE = 0,
64+
ACTION_CONTINUE,
65+
ACTION_SKIP,
66+
ACTION_ABORT,
67+
ACTION_QUIT,
68+
ACTION_EDIT_TODO,
69+
ACTION_SHOW_CURRENT_PATCH
70+
};
71+
72+
static const char *action_names[] = {
73+
"undefined",
74+
"continue",
75+
"skip",
76+
"abort",
77+
"quit",
78+
"edit_todo",
79+
"show_current_patch"
80+
};
81+
6282
struct rebase_options {
6383
enum rebase_type type;
6484
enum empty_type empty;
@@ -85,7 +105,7 @@ struct rebase_options {
85105
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
86106
} flags;
87107
struct strvec git_am_opts;
88-
const char *action;
108+
enum action action;
89109
int signoff;
90110
int allow_rerere_autoupdate;
91111
int keep_empty;
@@ -156,24 +176,6 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
156176
return replay;
157177
}
158178

159-
enum action {
160-
ACTION_NONE = 0,
161-
ACTION_CONTINUE,
162-
ACTION_SKIP,
163-
ACTION_ABORT,
164-
ACTION_QUIT,
165-
ACTION_EDIT_TODO,
166-
ACTION_SHOW_CURRENT_PATCH
167-
};
168-
169-
static const char *action_names[] = { "undefined",
170-
"continue",
171-
"skip",
172-
"abort",
173-
"quit",
174-
"edit_todo",
175-
"show_current_patch" };
176-
177179
static int edit_todo_file(unsigned flags)
178180
{
179181
const char *todo_file = rebase_path_todo();
@@ -310,8 +312,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
310312
return ret;
311313
}
312314

313-
static int run_sequencer_rebase(struct rebase_options *opts,
314-
enum action command)
315+
static int run_sequencer_rebase(struct rebase_options *opts)
315316
{
316317
unsigned flags = 0;
317318
int abbreviate_commands = 0, ret = 0;
@@ -326,7 +327,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
326327
flags |= opts->reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0;
327328
flags |= opts->flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0;
328329

329-
switch (command) {
330+
switch (opts->action) {
330331
case ACTION_NONE: {
331332
if (!opts->onto && !opts->upstream)
332333
die(_("a base commit must be provided with --upstream or --onto"));
@@ -359,7 +360,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
359360
break;
360361
}
361362
default:
362-
BUG("invalid command '%d'", command);
363+
BUG("invalid command '%d'", opts->action);
363364
}
364365

365366
return ret;
@@ -617,7 +618,7 @@ static int run_am(struct rebase_options *opts)
617618
strvec_push(&am.args, "am");
618619
strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
619620
getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
620-
if (opts->action && !strcmp("continue", opts->action)) {
621+
if (opts->action == ACTION_CONTINUE) {
621622
strvec_push(&am.args, "--resolved");
622623
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
623624
if (opts->gpg_sign_opt)
@@ -628,7 +629,7 @@ static int run_am(struct rebase_options *opts)
628629

629630
return move_to_original_branch(opts);
630631
}
631-
if (opts->action && !strcmp("skip", opts->action)) {
632+
if (opts->action == ACTION_SKIP) {
632633
strvec_push(&am.args, "--skip");
633634
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
634635
status = run_command(&am);
@@ -637,7 +638,7 @@ static int run_am(struct rebase_options *opts)
637638

638639
return move_to_original_branch(opts);
639640
}
640-
if (opts->action && !strcmp("show-current-patch", opts->action)) {
641+
if (opts->action == ACTION_SHOW_CURRENT_PATCH) {
641642
strvec_push(&am.args, "--show-current-patch");
642643
return run_command(&am);
643644
}
@@ -730,7 +731,7 @@ static int run_am(struct rebase_options *opts)
730731
return status;
731732
}
732733

733-
static int run_specific_rebase(struct rebase_options *opts, enum action action)
734+
static int run_specific_rebase(struct rebase_options *opts)
734735
{
735736
int status;
736737

@@ -748,7 +749,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action)
748749
opts->gpg_sign_opt = tmp;
749750
}
750751

751-
status = run_sequencer_rebase(opts, action);
752+
status = run_sequencer_rebase(opts);
752753
} else if (opts->type == REBASE_APPLY)
753754
status = run_am(opts);
754755
else
@@ -1025,7 +1026,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10251026
struct strbuf buf = STRBUF_INIT;
10261027
struct object_id branch_base;
10271028
int ignore_whitespace = 0;
1028-
enum action action = ACTION_NONE;
10291029
const char *gpg_sign = NULL;
10301030
struct string_list exec = STRING_LIST_INIT_NODUP;
10311031
const char *rebase_merges = NULL;
@@ -1074,18 +1074,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10741074
OPT_BIT(0, "no-ff", &options.flags,
10751075
N_("cherry-pick all commits, even if unchanged"),
10761076
REBASE_FORCE),
1077-
OPT_CMDMODE(0, "continue", &action, N_("continue"),
1077+
OPT_CMDMODE(0, "continue", &options.action, N_("continue"),
10781078
ACTION_CONTINUE),
1079-
OPT_CMDMODE(0, "skip", &action,
1079+
OPT_CMDMODE(0, "skip", &options.action,
10801080
N_("skip current patch and continue"), ACTION_SKIP),
1081-
OPT_CMDMODE(0, "abort", &action,
1081+
OPT_CMDMODE(0, "abort", &options.action,
10821082
N_("abort and check out the original branch"),
10831083
ACTION_ABORT),
1084-
OPT_CMDMODE(0, "quit", &action,
1084+
OPT_CMDMODE(0, "quit", &options.action,
10851085
N_("abort but keep HEAD where it is"), ACTION_QUIT),
1086-
OPT_CMDMODE(0, "edit-todo", &action, N_("edit the todo list "
1086+
OPT_CMDMODE(0, "edit-todo", &options.action, N_("edit the todo list "
10871087
"during an interactive rebase"), ACTION_EDIT_TODO),
1088-
OPT_CMDMODE(0, "show-current-patch", &action,
1088+
OPT_CMDMODE(0, "show-current-patch", &options.action,
10891089
N_("show the patch file being applied or merged"),
10901090
ACTION_SHOW_CURRENT_PATCH),
10911091
OPT_CALLBACK_F(0, "apply", &options, NULL,
@@ -1174,7 +1174,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11741174
} else if (is_directory(merge_dir())) {
11751175
strbuf_reset(&buf);
11761176
strbuf_addf(&buf, "%s/rewritten", merge_dir());
1177-
if (!(action == ACTION_ABORT) && is_directory(buf.buf)) {
1177+
if (!(options.action == ACTION_ABORT) && is_directory(buf.buf)) {
11781178
die(_("`rebase --preserve-merges` (-p) is no longer supported.\n"
11791179
"Use `git rebase --abort` to terminate current rebase.\n"
11801180
"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)
12011201
"Note: Your `pull.rebase` configuration may also be set to 'preserve',\n"
12021202
"which is no longer supported; use 'merges' instead"));
12031203

1204-
if (action != ACTION_NONE && total_argc != 2) {
1204+
if (options.action != ACTION_NONE && total_argc != 2) {
12051205
usage_with_options(builtin_rebase_usage,
12061206
builtin_rebase_options);
12071207
}
@@ -1232,11 +1232,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12321232
if (options.root && options.fork_point > 0)
12331233
die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point");
12341234

1235-
if (action != ACTION_NONE && !in_progress)
1235+
if (options.action != ACTION_NONE && !in_progress)
12361236
die(_("No rebase in progress?"));
12371237
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
12381238

1239-
if (action == ACTION_EDIT_TODO && !is_merge(&options))
1239+
if (options.action == ACTION_EDIT_TODO && !is_merge(&options))
12401240
die(_("The --edit-todo action can only be used during "
12411241
"interactive rebase."));
12421242

@@ -1246,16 +1246,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12461246
else if (exec.nr)
12471247
trace2_cmd_mode("interactive-exec");
12481248
else
1249-
trace2_cmd_mode(action_names[action]);
1249+
trace2_cmd_mode(action_names[options.action]);
12501250
}
12511251

1252-
switch (action) {
1252+
switch (options.action) {
12531253
case ACTION_CONTINUE: {
12541254
struct object_id head;
12551255
struct lock_file lock_file = LOCK_INIT;
12561256
int fd;
12571257

1258-
options.action = "continue";
12591258
/* Sanity check */
12601259
if (get_oid("HEAD", &head))
12611260
die(_("Cannot read HEAD"));
@@ -1281,7 +1280,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12811280
case ACTION_SKIP: {
12821281
struct string_list merge_rr = STRING_LIST_INIT_DUP;
12831282

1284-
options.action = "skip";
12851283
rerere_clear(the_repository, &merge_rr);
12861284
string_list_clear(&merge_rr, 1);
12871285
ropts.flags = RESET_HEAD_HARD;
@@ -1296,7 +1294,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12961294
struct string_list merge_rr = STRING_LIST_INIT_DUP;
12971295
struct strbuf head_msg = STRBUF_INIT;
12981296

1299-
options.action = "abort";
13001297
rerere_clear(the_repository, &merge_rr);
13011298
string_list_clear(&merge_rr, 1);
13021299

@@ -1336,17 +1333,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13361333
goto cleanup;
13371334
}
13381335
case ACTION_EDIT_TODO:
1339-
options.action = "edit-todo";
13401336
options.dont_finish_rebase = 1;
13411337
goto run_rebase;
13421338
case ACTION_SHOW_CURRENT_PATCH:
1343-
options.action = "show-current-patch";
13441339
options.dont_finish_rebase = 1;
13451340
goto run_rebase;
13461341
case ACTION_NONE:
13471342
break;
13481343
default:
1349-
BUG("action: %d", action);
1344+
BUG("action: %d", options.action);
13501345
}
13511346

13521347
/* Make sure no rebase is in progress */
@@ -1370,7 +1365,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13701365
}
13711366

13721367
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
1373-
(action != ACTION_NONE) ||
1368+
(options.action != ACTION_NONE) ||
13741369
(exec.nr > 0) ||
13751370
options.autosquash) {
13761371
allow_preemptive_ff = 0;
@@ -1815,7 +1810,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18151810
options.revisions = revisions.buf;
18161811

18171812
run_rebase:
1818-
ret = run_specific_rebase(&options, action);
1813+
ret = run_specific_rebase(&options);
18191814

18201815
cleanup:
18211816
strbuf_release(&buf);

0 commit comments

Comments
 (0)