Skip to content

Commit ebe8a2b

Browse files
committed
sequencer: factor out todo command name parsing
Factor out the code that parses the name of the command at the start of each line in the todo file into it's own function so that it can be used in the next commit. Signed-off-by: Phillip Wood <[email protected]>
1 parent a5bede1 commit ebe8a2b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

sequencer.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,18 @@ const char *todo_item_get_arg(struct todo_list *todo_list,
20762076
return todo_list->buf.buf + item->arg_offset;
20772077
}
20782078

2079+
static int is_command(enum todo_command command, const char **bol)
2080+
{
2081+
const char *str = todo_command_info[command].str;
2082+
const char nick = todo_command_info[command].c;
2083+
const char *p = *bol + 1;
2084+
2085+
return skip_prefix(*bol, str, bol) ||
2086+
((nick && **bol == nick) &&
2087+
(*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) &&
2088+
(*bol = p));
2089+
}
2090+
20792091
static int parse_insn_line(struct repository *r, struct todo_item *item,
20802092
const char *buf, const char *bol, char *eol)
20812093
{
@@ -2097,12 +2109,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
20972109
}
20982110

20992111
for (i = 0; i < TODO_COMMENT; i++)
2100-
if (skip_prefix(bol, todo_command_info[i].str, &bol)) {
2101-
item->command = i;
2102-
break;
2103-
} else if ((bol + 1 == eol || bol[1] == ' ' || bol[1] == '\t') &&
2104-
*bol == todo_command_info[i].c) {
2105-
bol++;
2112+
if (is_command(i, &bol)) {
21062113
item->command = i;
21072114
break;
21082115
}

0 commit comments

Comments
 (0)