Skip to content

Commit 297b1e1

Browse files
phillipwoodgitster
authored andcommitted
rebase: use a common action enum
cmd_rebase() and cmd_rebase__interactive() used different enums to hold the current action. Change to using a common enum so the values are the same when we change `rebase -i` to avoid forking `rebase--interactive`. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ea0847 commit 297b1e1

File tree

1 file changed

+48
-43
lines changed

1 file changed

+48
-43
lines changed

builtin/rebase.c

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
119119
return replay;
120120
}
121121

122+
enum action {
123+
ACTION_NONE = 0,
124+
ACTION_CONTINUE,
125+
ACTION_SKIP,
126+
ACTION_ABORT,
127+
ACTION_QUIT,
128+
ACTION_EDIT_TODO,
129+
ACTION_SHOW_CURRENT_PATCH,
130+
ACTION_SHORTEN_OIDS,
131+
ACTION_EXPAND_OIDS,
132+
ACTION_CHECK_TODO_LIST,
133+
ACTION_REARRANGE_SQUASH,
134+
ACTION_ADD_EXEC
135+
};
136+
137+
static const char *action_names[] = { "undefined",
138+
"continue",
139+
"skip",
140+
"abort",
141+
"quit",
142+
"edit_todo",
143+
"show_current_patch" };
144+
122145
static int add_exec_commands(struct string_list *commands)
123146
{
124147
const char *todo_file = rebase_path_todo();
@@ -347,10 +370,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
347370
unsigned flags = 0;
348371
int abbreviate_commands = 0, ret = 0;
349372
struct object_id squash_onto = null_oid;
350-
enum {
351-
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH,
352-
SHORTEN_OIDS, EXPAND_OIDS, CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC
353-
} command = 0;
373+
enum action command = ACTION_NONE;
354374
struct option options[] = {
355375
OPT_NEGBIT(0, "ff", &opts.flags, N_("allow fast-forward"),
356376
REBASE_FORCE),
@@ -367,22 +387,22 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
367387
N_("display a diffstat of what changed upstream"),
368388
REBASE_NO_QUIET | REBASE_VERBOSE | REBASE_DIFFSTAT),
369389
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
370-
CONTINUE),
371-
OPT_CMDMODE(0, "skip", &command, N_("skip commit"), SKIP),
390+
ACTION_CONTINUE),
391+
OPT_CMDMODE(0, "skip", &command, N_("skip commit"), ACTION_SKIP),
372392
OPT_CMDMODE(0, "edit-todo", &command, N_("edit the todo list"),
373-
EDIT_TODO),
393+
ACTION_EDIT_TODO),
374394
OPT_CMDMODE(0, "show-current-patch", &command, N_("show the current patch"),
375-
SHOW_CURRENT_PATCH),
395+
ACTION_SHOW_CURRENT_PATCH),
376396
OPT_CMDMODE(0, "shorten-ids", &command,
377-
N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
397+
N_("shorten commit ids in the todo list"), ACTION_SHORTEN_OIDS),
378398
OPT_CMDMODE(0, "expand-ids", &command,
379-
N_("expand commit ids in the todo list"), EXPAND_OIDS),
399+
N_("expand commit ids in the todo list"), ACTION_EXPAND_OIDS),
380400
OPT_CMDMODE(0, "check-todo-list", &command,
381-
N_("check the todo list"), CHECK_TODO_LIST),
401+
N_("check the todo list"), ACTION_CHECK_TODO_LIST),
382402
OPT_CMDMODE(0, "rearrange-squash", &command,
383-
N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
403+
N_("rearrange fixup/squash lines"), ACTION_REARRANGE_SQUASH),
384404
OPT_CMDMODE(0, "add-exec-commands", &command,
385-
N_("insert exec commands in todo list"), ADD_EXEC),
405+
N_("insert exec commands in todo list"), ACTION_ADD_EXEC),
386406
{ OPTION_CALLBACK, 0, "onto", &opts.onto, N_("onto"), N_("onto"),
387407
PARSE_OPT_NONEG, parse_opt_commit, 0 },
388408
{ OPTION_CALLBACK, 0, "restrict-revision", &opts.restrict_revision,
@@ -428,36 +448,36 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
428448
flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
429449
flags |= opts.rebase_merges ? TODO_LIST_REBASE_MERGES : 0;
430450
flags |= opts.rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0;
431-
flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
451+
flags |= command == ACTION_SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
432452

433453
if (opts.rebase_cousins >= 0 && !opts.rebase_merges)
434454
warning(_("--[no-]rebase-cousins has no effect without "
435455
"--rebase-merges"));
436456

437457
switch (command) {
438-
case NONE: {
458+
case ACTION_NONE: {
439459
if (!opts.onto && !opts.upstream)
440460
die(_("a base commit must be provided with --upstream or --onto"));
441461

442462
ret = do_interactive_rebase(&opts, flags);
443463
break;
444464
}
445-
case SKIP: {
465+
case ACTION_SKIP: {
446466
struct string_list merge_rr = STRING_LIST_INIT_DUP;
447467

448468
rerere_clear(the_repository, &merge_rr);
449469
}
450470
/* fallthrough */
451-
case CONTINUE: {
471+
case ACTION_CONTINUE: {
452472
struct replay_opts replay_opts = get_replay_opts(&opts);
453473

454474
ret = sequencer_continue(the_repository, &replay_opts);
455475
break;
456476
}
457-
case EDIT_TODO:
477+
case ACTION_EDIT_TODO:
458478
ret = edit_todo_file(flags);
459479
break;
460-
case SHOW_CURRENT_PATCH: {
480+
case ACTION_SHOW_CURRENT_PATCH: {
461481
struct child_process cmd = CHILD_PROCESS_INIT;
462482

463483
cmd.git_cmd = 1;
@@ -466,17 +486,17 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
466486

467487
break;
468488
}
469-
case SHORTEN_OIDS:
470-
case EXPAND_OIDS:
489+
case ACTION_SHORTEN_OIDS:
490+
case ACTION_EXPAND_OIDS:
471491
ret = transform_todo_file(flags);
472492
break;
473-
case CHECK_TODO_LIST:
493+
case ACTION_CHECK_TODO_LIST:
474494
ret = check_todo_list_from_file(the_repository);
475495
break;
476-
case REARRANGE_SQUASH:
496+
case ACTION_REARRANGE_SQUASH:
477497
ret = rearrange_squash_in_todo_file();
478498
break;
479-
case ADD_EXEC: {
499+
case ACTION_ADD_EXEC: {
480500
struct string_list commands = STRING_LIST_INIT_DUP;
481501

482502
split_exec_commands(opts.cmd, &commands);
@@ -1417,22 +1437,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14171437
struct strbuf revisions = STRBUF_INIT;
14181438
struct strbuf buf = STRBUF_INIT;
14191439
struct object_id merge_base;
1420-
enum {
1421-
NO_ACTION,
1422-
ACTION_CONTINUE,
1423-
ACTION_SKIP,
1424-
ACTION_ABORT,
1425-
ACTION_QUIT,
1426-
ACTION_EDIT_TODO,
1427-
ACTION_SHOW_CURRENT_PATCH,
1428-
} action = NO_ACTION;
1429-
static const char *action_names[] = { "undefined",
1430-
"continue",
1431-
"skip",
1432-
"abort",
1433-
"quit",
1434-
"edit_todo",
1435-
"show_current_patch" };
1440+
enum action action = ACTION_NONE;
14361441
const char *gpg_sign = NULL;
14371442
struct string_list exec = STRING_LIST_INIT_NODUP;
14381443
const char *rebase_merges = NULL;
@@ -1599,7 +1604,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15991604
builtin_rebase_options,
16001605
builtin_rebase_usage, 0);
16011606

1602-
if (action != NO_ACTION && total_argc != 2) {
1607+
if (action != ACTION_NONE && total_argc != 2) {
16031608
usage_with_options(builtin_rebase_usage,
16041609
builtin_rebase_options);
16051610
}
@@ -1608,7 +1613,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
16081613
usage_with_options(builtin_rebase_usage,
16091614
builtin_rebase_options);
16101615

1611-
if (action != NO_ACTION && !in_progress)
1616+
if (action != ACTION_NONE && !in_progress)
16121617
die(_("No rebase in progress?"));
16131618
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
16141619

@@ -1708,7 +1713,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17081713
options.action = "show-current-patch";
17091714
options.dont_finish_rebase = 1;
17101715
goto run_rebase;
1711-
case NO_ACTION:
1716+
case ACTION_NONE:
17121717
break;
17131718
default:
17141719
BUG("action: %d", action);

0 commit comments

Comments
 (0)