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>
Phillip Wood committed
Oct 12, 2022 at 09:35 UTC
9a1925b08f3d9b71f06226f5ac32f24587f39151
1 file changed
+44
-49
builtin/rebase.c
+44
-49
@@ -59,6 +59,26 @@ enum empty_type {
59
EMPTY_ASK
60
};
61
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
+
82
struct rebase_options {
83
enum rebase_type type;
84
enum empty_type empty;
@@ -85,7 +105,7 @@ struct rebase_options {
105
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
106
} flags;
107
struct strvec git_am_opts;
88
- const char *action;
108
+ enum action action;
109
int signoff;
110
int allow_rerere_autoupdate;
111
int keep_empty;
@@ -156,24 +176,6 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
176
return replay;
177
}
178
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
-
179
static int edit_todo_file(unsigned flags)
180
{
181
const char *todo_file = rebase_path_todo();
@@ -310,8 +312,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
312
return ret;
313
}
314
313
-static int run_sequencer_rebase(struct rebase_options *opts,
314
- enum action command)
315
+static int run_sequencer_rebase(struct rebase_options *opts)
316
{
317
unsigned flags = 0;
318
int abbreviate_commands = 0, ret = 0;
@@ -326,7 +327,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
327
flags |= opts->reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0;
328
flags |= opts->flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0;
329
329
- switch (command) {
330
+ switch (opts->action) {
331
case ACTION_NONE: {
332
if (!opts->onto && !opts->upstream)
333
die(_("a base commit must be provided with --upstream or --onto"));
@@ -359,7 +360,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
360
break;
361
}
362
default:
362
- BUG("invalid command '%d'", command);
363
+ BUG("invalid command '%d'", opts->action);
364
}
365
366
return ret;
@@ -617,7 +618,7 @@ static int run_am(struct rebase_options *opts)
618
strvec_push(&am.args, "am");
619
strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
620
getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
620
- if (opts->action && !strcmp("continue", opts->action)) {
621
+ if (opts->action == ACTION_CONTINUE) {
622
strvec_push(&am.args, "--resolved");
623
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
624
if (opts->gpg_sign_opt)
@@ -628,7 +629,7 @@ static int run_am(struct rebase_options *opts)
629
630
return move_to_original_branch(opts);
631
}
631
- if (opts->action && !strcmp("skip", opts->action)) {
632
+ if (opts->action == ACTION_SKIP) {
633
strvec_push(&am.args, "--skip");
634
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
635
status = run_command(&am);
@@ -637,7 +638,7 @@ static int run_am(struct rebase_options *opts)
638
639
return move_to_original_branch(opts);
640
}
640
- if (opts->action && !strcmp("show-current-patch", opts->action)) {
641
+ if (opts->action == ACTION_SHOW_CURRENT_PATCH) {
642
strvec_push(&am.args, "--show-current-patch");
643
return run_command(&am);
644
}
@@ -730,7 +731,7 @@ static int run_am(struct rebase_options *opts)
731
return status;
732
}
733
733
-static int run_specific_rebase(struct rebase_options *opts, enum action action)
734
+static int run_specific_rebase(struct rebase_options *opts)
735
{
736
int status;
737
@@ -748,7 +749,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action)
749
opts->gpg_sign_opt = tmp;
750
}
751
751
- status = run_sequencer_rebase(opts, action);
752
+ status = run_sequencer_rebase(opts);
753
} else if (opts->type == REBASE_APPLY)
754
status = run_am(opts);
755
else
@@ -1025,7 +1026,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1026
struct strbuf buf = STRBUF_INIT;
1027
struct object_id branch_base;
1028
int ignore_whitespace = 0;
1028
- enum action action = ACTION_NONE;
1029
const char *gpg_sign = NULL;
1030
struct string_list exec = STRING_LIST_INIT_NODUP;
1031
const char *rebase_merges = NULL;
@@ -1074,18 +1074,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1074
OPT_BIT(0, "no-ff", &options.flags,
1075
N_("cherry-pick all commits, even if unchanged"),
1076
REBASE_FORCE),
1077
- OPT_CMDMODE(0, "continue", &action, N_("continue"),
1077
+ OPT_CMDMODE(0, "continue", &options.action, N_("continue"),
1078
ACTION_CONTINUE),
1079
- OPT_CMDMODE(0, "skip", &action,
1079
+ OPT_CMDMODE(0, "skip", &options.action,
1080
N_("skip current patch and continue"), ACTION_SKIP),
1081
- OPT_CMDMODE(0, "abort", &action,
1081
+ OPT_CMDMODE(0, "abort", &options.action,
1082
N_("abort and check out the original branch"),
1083
ACTION_ABORT),
1084
- OPT_CMDMODE(0, "quit", &action,
1084
+ OPT_CMDMODE(0, "quit", &options.action,
1085
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 "
1087
"during an interactive rebase"), ACTION_EDIT_TODO),
1088
- OPT_CMDMODE(0, "show-current-patch", &action,
1088
+ OPT_CMDMODE(0, "show-current-patch", &options.action,
1089
N_("show the patch file being applied or merged"),
1090
ACTION_SHOW_CURRENT_PATCH),
1091
OPT_CALLBACK_F(0, "apply", &options, NULL,
@@ -1174,7 +1174,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1174
} else if (is_directory(merge_dir())) {
1175
strbuf_reset(&buf);
1176
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)) {
1178
die(_("`rebase --preserve-merges` (-p) is no longer supported.\n"
1179
"Use `git rebase --abort` to terminate current rebase.\n"
1180
"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)
1201
"Note: Your `pull.rebase` configuration may also be set to 'preserve',\n"
1202
"which is no longer supported; use 'merges' instead"));
1203
1204
- if (action != ACTION_NONE && total_argc != 2) {
1204
+ if (options.action != ACTION_NONE && total_argc != 2) {
1205
usage_with_options(builtin_rebase_usage,
1206
builtin_rebase_options);
1207
}
@@ -1232,11 +1232,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1232
if (options.root && options.fork_point > 0)
1233
die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point");
1234
1235
- if (action != ACTION_NONE && !in_progress)
1235
+ if (options.action != ACTION_NONE && !in_progress)
1236
die(_("No rebase in progress?"));
1237
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
1238
1239
- if (action == ACTION_EDIT_TODO && !is_merge(&options))
1239
+ if (options.action == ACTION_EDIT_TODO && !is_merge(&options))
1240
die(_("The --edit-todo action can only be used during "
1241
"interactive rebase."));
1242
@@ -1246,16 +1246,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1246
else if (exec.nr)
1247
trace2_cmd_mode("interactive-exec");
1248
else
1249
- trace2_cmd_mode(action_names[action]);
1249
+ trace2_cmd_mode(action_names[options.action]);
1250
}
1251
1252
- switch (action) {
1252
+ switch (options.action) {
1253
case ACTION_CONTINUE: {
1254
struct object_id head;
1255
struct lock_file lock_file = LOCK_INIT;
1256
int fd;
1257
1258
- options.action = "continue";
1258
/* Sanity check */
1259
if (get_oid("HEAD", &head))
1260
die(_("Cannot read HEAD"));
@@ -1281,7 +1280,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1280
case ACTION_SKIP: {
1281
struct string_list merge_rr = STRING_LIST_INIT_DUP;
1282
1284
- options.action = "skip";
1283
rerere_clear(the_repository, &merge_rr);
1284
string_list_clear(&merge_rr, 1);
1285
ropts.flags = RESET_HEAD_HARD;
@@ -1296,7 +1294,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1294
struct string_list merge_rr = STRING_LIST_INIT_DUP;
1295
struct strbuf head_msg = STRBUF_INIT;
1296
1299
- options.action = "abort";
1297
rerere_clear(the_repository, &merge_rr);
1298
string_list_clear(&merge_rr, 1);
1299
@@ -1336,17 +1333,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1333
goto cleanup;
1334
}
1335
case ACTION_EDIT_TODO:
1339
- options.action = "edit-todo";
1336
options.dont_finish_rebase = 1;
1337
goto run_rebase;
1338
case ACTION_SHOW_CURRENT_PATCH:
1343
- options.action = "show-current-patch";
1339
options.dont_finish_rebase = 1;
1340
goto run_rebase;
1341
case ACTION_NONE:
1342
break;
1343
default:
1349
- BUG("action: %d", action);
1344
+ BUG("action: %d", options.action);
1345
}
1346
1347
/* Make sure no rebase is in progress */
@@ -1370,7 +1365,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1365
}
1366
1367
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
1373
- (action != ACTION_NONE) ||
1368
+ (options.action != ACTION_NONE) ||
1369
(exec.nr > 0) ||
1370
options.autosquash) {
1371
allow_preemptive_ff = 0;
@@ -1815,7 +1810,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1810
options.revisions = revisions.buf;
1811
1812
run_rebase:
1818
- ret = run_specific_rebase(&options, action);
1813
+ ret = run_specific_rebase(&options);
1814
1815
cleanup:
1816
strbuf_release(&buf);