Skip to content

Commit 25c4366

Browse files
dschogitster
authored andcommitted
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>
1 parent 8458395 commit 25c4366

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

sequencer.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,23 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit)
607607
return 1;
608608
}
609609

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+
*/
610615
enum todo_command {
616+
/* commands that handle commits */
611617
TODO_PICK = 0,
612-
TODO_REVERT
618+
TODO_REVERT,
619+
/* commands that do nothing but are counted for reporting progress */
620+
TODO_NOOP
613621
};
614622

615623
static const char *todo_command_strings[] = {
616624
"pick",
617-
"revert"
625+
"revert",
626+
"noop"
618627
};
619628

620629
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)
624633
die("Unknown command: %d", command);
625634
}
626635

636+
static int is_noop(const enum todo_command command)
637+
{
638+
return TODO_NOOP <= (size_t)command;
639+
}
627640

628641
static int do_pick_commit(enum todo_command command, struct commit *commit,
629642
struct replay_opts *opts)
@@ -879,6 +892,14 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
879892
/* left-trim */
880893
bol += strspn(bol, " \t");
881894

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+
882903
for (i = 0; i < ARRAY_SIZE(todo_command_strings); i++)
883904
if (skip_prefix(bol, todo_command_strings[i], &bol)) {
884905
item->command = i;
@@ -887,6 +908,13 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
887908
if (i >= ARRAY_SIZE(todo_command_strings))
888909
return -1;
889910

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+
890918
/* Eat up extra spaces/ tabs before object name */
891919
padding = strspn(bol, " \t");
892920
if (!padding)
@@ -1289,7 +1317,12 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
12891317
struct todo_item *item = todo_list->items + todo_list->current;
12901318
if (save_todo(todo_list, opts))
12911319
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+
12931326
todo_list->current++;
12941327
if (res)
12951328
return res;

0 commit comments

Comments
 (0)