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

Phillip Wood committed Apr 17, 2019 at 15:30 UTC 297b1e177377444cba9a5364a4c6ce676ededb4d
1 file changed +48 -43
builtin/rebase.c
+48 -43
@@ -119,6 +119,29 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
119 return replay;
120 }
121
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 +
145 static int add_exec_commands(struct string_list *commands)
146 {
147 const char *todo_file = rebase_path_todo();
@@ -347,10 +370,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
370 unsigned flags = 0;
371 int abbreviate_commands = 0, ret = 0;
372 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;
374 struct option options[] = {
375 OPT_NEGBIT(0, "ff", &opts.flags, N_("allow fast-forward"),
376 REBASE_FORCE),
@@ -367,22 +387,22 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
387 N_("display a diffstat of what changed upstream"),
388 REBASE_NO_QUIET | REBASE_VERBOSE | REBASE_DIFFSTAT),
389 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),
392 OPT_CMDMODE(0, "edit-todo", &command, N_("edit the todo list"),
373 - EDIT_TODO),
393 + ACTION_EDIT_TODO),
394 OPT_CMDMODE(0, "show-current-patch", &command, N_("show the current patch"),
375 - SHOW_CURRENT_PATCH),
395 + ACTION_SHOW_CURRENT_PATCH),
396 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),
398 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),
400 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),
402 OPT_CMDMODE(0, "rearrange-squash", &command,
383 - N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
403 + N_("rearrange fixup/squash lines"), ACTION_REARRANGE_SQUASH),
404 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),
406 { OPTION_CALLBACK, 0, "onto", &opts.onto, N_("onto"), N_("onto"),
407 PARSE_OPT_NONEG, parse_opt_commit, 0 },
408 { OPTION_CALLBACK, 0, "restrict-revision", &opts.restrict_revision,
@@ -428,36 +448,36 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
448 flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
449 flags |= opts.rebase_merges ? TODO_LIST_REBASE_MERGES : 0;
450 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;
452
453 if (opts.rebase_cousins >= 0 && !opts.rebase_merges)
454 warning(_("--[no-]rebase-cousins has no effect without "
455 "--rebase-merges"));
456
457 switch (command) {
438 - case NONE: {
458 + case ACTION_NONE: {
459 if (!opts.onto && !opts.upstream)
460 die(_("a base commit must be provided with --upstream or --onto"));
461
462 ret = do_interactive_rebase(&opts, flags);
463 break;
464 }
445 - case SKIP: {
465 + case ACTION_SKIP: {
466 struct string_list merge_rr = STRING_LIST_INIT_DUP;
467
468 rerere_clear(the_repository, &merge_rr);
469 }
470 /* fallthrough */
451 - case CONTINUE: {
471 + case ACTION_CONTINUE: {
472 struct replay_opts replay_opts = get_replay_opts(&opts);
473
474 ret = sequencer_continue(the_repository, &replay_opts);
475 break;
476 }
457 - case EDIT_TODO:
477 + case ACTION_EDIT_TODO:
478 ret = edit_todo_file(flags);
479 break;
460 - case SHOW_CURRENT_PATCH: {
480 + case ACTION_SHOW_CURRENT_PATCH: {
481 struct child_process cmd = CHILD_PROCESS_INIT;
482
483 cmd.git_cmd = 1;
@@ -466,17 +486,17 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
486
487 break;
488 }
469 - case SHORTEN_OIDS:
470 - case EXPAND_OIDS:
489 + case ACTION_SHORTEN_OIDS:
490 + case ACTION_EXPAND_OIDS:
491 ret = transform_todo_file(flags);
492 break;
473 - case CHECK_TODO_LIST:
493 + case ACTION_CHECK_TODO_LIST:
494 ret = check_todo_list_from_file(the_repository);
495 break;
476 - case REARRANGE_SQUASH:
496 + case ACTION_REARRANGE_SQUASH:
497 ret = rearrange_squash_in_todo_file();
498 break;
479 - case ADD_EXEC: {
499 + case ACTION_ADD_EXEC: {
500 struct string_list commands = STRING_LIST_INIT_DUP;
501
502 split_exec_commands(opts.cmd, &commands);
@@ -1417,22 +1437,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1437 struct strbuf revisions = STRBUF_INIT;
1438 struct strbuf buf = STRBUF_INIT;
1439 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;
1441 const char *gpg_sign = NULL;
1442 struct string_list exec = STRING_LIST_INIT_NODUP;
1443 const char *rebase_merges = NULL;
@@ -1599,7 +1604,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1604 builtin_rebase_options,
1605 builtin_rebase_usage, 0);
1606
1602 - if (action != NO_ACTION && total_argc != 2) {
1607 + if (action != ACTION_NONE && total_argc != 2) {
1608 usage_with_options(builtin_rebase_usage,
1609 builtin_rebase_options);
1610 }
@@ -1608,7 +1613,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1613 usage_with_options(builtin_rebase_usage,
1614 builtin_rebase_options);
1615
1611 - if (action != NO_ACTION && !in_progress)
1616 + if (action != ACTION_NONE && !in_progress)
1617 die(_("No rebase in progress?"));
1618 setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
1619
@@ -1708,7 +1713,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1713 options.action = "show-current-patch";
1714 options.dont_finish_rebase = 1;
1715 goto run_rebase;
1711 - case NO_ACTION:
1716 + case ACTION_NONE:
1717 break;
1718 default:
1719 BUG("action: %d", action);