Skip to content

Commit 7b8e518

Browse files
committed
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>
1 parent e8095a4 commit 7b8e518

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

sequencer.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -621,20 +621,23 @@ enum todo_command {
621621
TODO_NOOP
622622
};
623623

624-
static const char *todo_command_strings[] = {
625-
"pick",
626-
"revert",
627-
"edit",
628-
"fixup",
629-
"squash",
630-
"exec",
631-
"noop"
624+
static struct {
625+
char c;
626+
const char *str;
627+
} todo_command_info[] = {
628+
{ 'p', "pick" },
629+
{ 0, "revert" },
630+
{ 'e', "edit" },
631+
{ 'f', "fixup" },
632+
{ 's', "squash" },
633+
{ 'x', "exec" },
634+
{ 0, "noop" }
632635
};
633636

634637
static const char *command_to_string(const enum todo_command command)
635638
{
636-
if (command >= 0 && command < ARRAY_SIZE(todo_command_strings))
637-
return todo_command_strings[command];
639+
if (command >= 0 && command < ARRAY_SIZE(todo_command_info))
640+
return todo_command_info[command].str;
638641
die("Unknown command: %d", command);
639642
}
640643

@@ -1030,12 +1033,17 @@ static int parse_insn_line(struct todo_item *item,
10301033
return 0;
10311034
}
10321035

1033-
for (i = 0; i < ARRAY_SIZE(todo_command_strings); i++)
1034-
if (skip_prefix(bol, todo_command_strings[i], &bol)) {
1036+
for (i = 0; i < ARRAY_SIZE(todo_command_info); i++)
1037+
if (skip_prefix(bol, todo_command_info[i].str, &bol)) {
10351038
item->command = i;
10361039
break;
10371040
}
1038-
if (i >= ARRAY_SIZE(todo_command_strings))
1041+
else if (bol[1] == ' ' && *bol == todo_command_info[i].c) {
1042+
bol++;
1043+
item->command = i;
1044+
break;
1045+
}
1046+
if (i >= ARRAY_SIZE(todo_command_info))
10391047
return error("Invalid command: %.*s", (int)(eol - bol), bol);
10401048

10411049
if (item->command == TODO_NOOP) {

0 commit comments

Comments
 (0)