sequencer (rebase -i): implement the 'noop' command

The 'noop' command is probably the most boring of all rebase -i commands to support in the sequencer. Which makes it an excellent candidate for this first stab to add support for rebase -i's commands to the sequencer. For the moment, let's also treat empty lines and commented-out lines as 'noop'; We will refine that handling later in this patch series. To make it easier to identify "classes" of todo_commands (such as: determine whether a command is pick-like, i.e. handles a single commit), let's enforce a certain order of said commands. 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:26 UTC 25c4366782ea941baad3b09d4b9ef63996f1e3b1
1 file changed +36 -3
sequencer.c
+36 -3
@@ -607,14 +607,23 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit)
607 return 1;
608 }
609
610 +/*
611 + * Note that ordering matters in this enum. Not only must it match the mapping
612 + * below, it is also divided into several sections that matter. When adding
613 + * new commands, make sure you add it in the right section.
614 + */
615 enum todo_command {
616 + /* commands that handle commits */
617 TODO_PICK = 0,
612 - TODO_REVERT
618 + TODO_REVERT,
619 + /* commands that do nothing but are counted for reporting progress */
620 + TODO_NOOP
621 };
622
623 static const char *todo_command_strings[] = {
624 "pick",
617 - "revert"
625 + "revert",
626 + "noop"
627 };
628
629 static const char *command_to_string(const enum todo_command command)
@@ -624,6 +633,10 @@ static const char *command_to_string(const enum todo_command command)
633 die("Unknown command: %d", command);
634 }
635
636 +static int is_noop(const enum todo_command command)
637 +{
638 + return TODO_NOOP <= (size_t)command;
639 +}
640
641 static int do_pick_commit(enum todo_command command, struct commit *commit,
642 struct replay_opts *opts)
@@ -879,6 +892,14 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
892 /* left-trim */
893 bol += strspn(bol, " \t");
894
895 + if (bol == eol || *bol == '\r' || *bol == comment_line_char) {
896 + item->command = TODO_NOOP;
897 + item->commit = NULL;
898 + item->arg = bol;
899 + item->arg_len = eol - bol;
900 + return 0;
901 + }
902 +
903 for (i = 0; i < ARRAY_SIZE(todo_command_strings); i++)
904 if (skip_prefix(bol, todo_command_strings[i], &bol)) {
905 item->command = i;
@@ -887,6 +908,13 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
908 if (i >= ARRAY_SIZE(todo_command_strings))
909 return -1;
910
911 + if (item->command == TODO_NOOP) {
912 + item->commit = NULL;
913 + item->arg = bol;
914 + item->arg_len = eol - bol;
915 + return 0;
916 + }
917 +
918 /* Eat up extra spaces/ tabs before object name */
919 padding = strspn(bol, " \t");
920 if (!padding)
@@ -1289,7 +1317,12 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
1317 struct todo_item *item = todo_list->items + todo_list->current;
1318 if (save_todo(todo_list, opts))
1319 return -1;
1292 - res = do_pick_commit(item->command, item->commit, opts);
1320 + if (item->command <= TODO_REVERT)
1321 + res = do_pick_commit(item->command, item->commit,
1322 + opts);
1323 + else if (!is_noop(item->command))
1324 + return error(_("unknown command %d"), item->command);
1325 +
1326 todo_list->current++;
1327 if (res)
1328 return res;