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.

Signed-off-by: Johannes Schindelin <johannes.schinde...@gmx.de>
---
 sequencer.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 5598534..f85dc9c 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -644,12 +644,14 @@ static int allow_empty(struct replay_opts *opts, struct 
commit *commit)
 
 enum todo_command {
        TODO_PICK,
-       TODO_REVERT
+       TODO_REVERT,
+       TODO_NOOP
 };
 
 static const char *todo_command_strings[] = {
        "pick",
-       "revert"
+       "revert",
+       "noop"
 };
 
 static const char *command_to_string(const enum todo_command command)
@@ -916,6 +918,14 @@ static int parse_insn_line(struct todo_item *item, const 
char *bol, char *eol)
        /* left-trim */
        bol += strspn(bol, " \t");
 
+       if (bol == eol || *bol == '\r' || *bol == comment_line_char) {
+               item->command = TODO_NOOP;
+               item->commit = NULL;
+               item->arg = bol;
+               item->arg_len = eol - bol;
+               return 0;
+       }
+
        for (i = 0; i < ARRAY_SIZE(todo_command_strings); i++)
                if (skip_prefix(bol, todo_command_strings[i], &bol)) {
                        item->command = i;
@@ -924,6 +934,13 @@ static int parse_insn_line(struct todo_item *item, const 
char *bol, char *eol)
        if (i >= ARRAY_SIZE(todo_command_strings))
                return -1;
 
+       if (item->command == TODO_NOOP) {
+               item->commit = NULL;
+               item->arg = bol;
+               item->arg_len = eol - bol;
+               return 0;
+       }
+
        /* Eat up extra spaces/ tabs before object name */
        padding = strspn(bol, " \t");
        if (!padding)
@@ -1277,7 +1294,12 @@ static int pick_commits(struct todo_list *todo_list, 
struct replay_opts *opts)
                struct todo_item *item = todo_list->items + todo_list->current;
                if (save_todo(todo_list, opts))
                        return -1;
-               res = do_pick_commit(item->command, item->commit, opts);
+               if (item->command <= TODO_REVERT)
+                       res = do_pick_commit(item->command, item->commit,
+                                       opts);
+               else if (item->command != TODO_NOOP)
+                       return error("Unknown command %d", item->command);
+
                todo_list->current++;
                if (res)
                        return res;
-- 
2.10.0.rc2.102.g5c102ec


Reply via email to