From: Junio C Hamano Date: Wed, 1 Mar 2023 00:38:47 +0000 (-0800) Subject: Merge branch 'pw/rebase-i-parse-fix' X-Git-Tag: v2.40.0-rc1~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a2d2b5229e55742f56fbbde4f7bb013171f7a6ca;p=thirdparty%2Fgit.git Merge branch 'pw/rebase-i-parse-fix' Fixes to code that parses the todo file used in "rebase -i". * pw/rebase-i-parse-fix: rebase -i: fix parsing of "fixup -C" rebase -i: match whole word in is_command() --- a2d2b5229e55742f56fbbde4f7bb013171f7a6ca diff --cc sequencer.c index a7e6db4f78,3c34e70872..1c96a75b1e --- a/sequencer.c +++ b/sequencer.c @@@ -2479,42 -2469,13 +2479,41 @@@ static int is_command(enum todo_comman { const char *str = todo_command_info[command].str; const char nick = todo_command_info[command].c; - const char *p = *bol + 1; + const char *p = *bol; - return skip_prefix(*bol, str, bol) || - ((nick && **bol == nick) && - (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) && - (*bol = p)); + return (skip_prefix(p, str, &p) || (nick && *p++ == nick)) && + (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) && + (*bol = p); } +static int check_label_or_ref_arg(enum todo_command command, const char *arg) +{ + switch (command) { + case TODO_LABEL: + /* + * '#' is not a valid label as the merge command uses it to + * separate merge parents from the commit subject. + */ + if (!strcmp(arg, "#") || + check_refname_format(arg, REFNAME_ALLOW_ONELEVEL)) + return error(_("'%s' is not a valid label"), arg); + break; + + case TODO_UPDATE_REF: + if (check_refname_format(arg, REFNAME_ALLOW_ONELEVEL)) + return error(_("'%s' is not a valid refname"), arg); + if (check_refname_format(arg, 0)) + return error(_("update-ref requires a fully qualified " + "refname e.g. refs/heads/%s"), arg); + break; + + default: + BUG("unexpected todo_command"); + } + + return 0; +} + static int parse_insn_line(struct repository *r, struct todo_item *item, const char *buf, const char *bol, char *eol) {