mirror of
https://github.com/git/git.git
synced 2026-01-28 11:32:24 +00:00
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>
This commit is contained in:
35
sequencer.c
35
sequencer.c
@@ -642,14 +642,23 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that ordering matters in this enum. Not only must it match the mapping
|
||||
* below, it is also divided into several sections that matter. When adding
|
||||
* new commands, make sure you add it in the right section.
|
||||
*/
|
||||
enum todo_command {
|
||||
/* commands that handle commits */
|
||||
TODO_PICK = 0,
|
||||
TODO_REVERT
|
||||
TODO_REVERT,
|
||||
/* commands that do nothing but are counted for reporting progress */
|
||||
TODO_NOOP
|
||||
};
|
||||
|
||||
static const char *todo_command_strings[] = {
|
||||
"pick",
|
||||
"revert"
|
||||
"revert",
|
||||
"noop"
|
||||
};
|
||||
|
||||
static const char *command_to_string(const enum todo_command command)
|
||||
@@ -914,6 +923,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;
|
||||
@@ -922,6 +939,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)
|
||||
@@ -1281,7 +1305,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;
|
||||
|
||||
Reference in New Issue
Block a user