sequencer (rebase -i): implement the short commands

For users' convenience, most rebase commands can be abbreviated, e.g. 'p' instead of 'pick' and 'x' instead of 'exec'. Let's teach the sequencer to handle those abbreviated commands just fine. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 2, 2017 at 16:27 UTC 414697a9d82079851a4623b01d6b3a125919d026
1 file changed +21 -14
sequencer.c
+21 -14
@@ -678,20 +678,23 @@ enum todo_command {
678 TODO_NOOP
679 };
680
681 -static const char *todo_command_strings[] = {
682 - "pick",
683 - "revert",
684 - "edit",
685 - "fixup",
686 - "squash",
687 - "exec",
688 - "noop"
681 +static struct {
682 + char c;
683 + const char *str;
684 +} todo_command_info[] = {
685 + { 'p', "pick" },
686 + { 0, "revert" },
687 + { 'e', "edit" },
688 + { 'f', "fixup" },
689 + { 's', "squash" },
690 + { 'x', "exec" },
691 + { 0, "noop" }
692 };
693
694 static const char *command_to_string(const enum todo_command command)
695 {
693 - if ((size_t)command < ARRAY_SIZE(todo_command_strings))
694 - return todo_command_strings[command];
696 + if ((size_t)command < ARRAY_SIZE(todo_command_info))
697 + return todo_command_info[command].str;
698 die("Unknown command: %d", command);
699 }
700
@@ -1087,12 +1090,16 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
1090 return 0;
1091 }
1092
1090 - for (i = 0; i < ARRAY_SIZE(todo_command_strings); i++)
1091 - if (skip_prefix(bol, todo_command_strings[i], &bol)) {
1093 + for (i = 0; i < ARRAY_SIZE(todo_command_info); i++)
1094 + if (skip_prefix(bol, todo_command_info[i].str, &bol)) {
1095 + item->command = i;
1096 + break;
1097 + } else if (bol[1] == ' ' && *bol == todo_command_info[i].c) {
1098 + bol++;
1099 item->command = i;
1100 break;
1101 }
1095 - if (i >= ARRAY_SIZE(todo_command_strings))
1102 + if (i >= ARRAY_SIZE(todo_command_info))
1103 return -1;
1104
1105 if (item->command == TODO_NOOP) {
@@ -1287,7 +1294,7 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
1294 {
1295 enum todo_command command = opts->action == REPLAY_PICK ?
1296 TODO_PICK : TODO_REVERT;
1290 - const char *command_string = todo_command_strings[command];
1297 + const char *command_string = todo_command_info[command].str;
1298 struct commit *commit;
1299
1300 if (prepare_revs(opts))