forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sequencer parsing fixes #1486
Closed
phillipwood
wants to merge
2
commits into
gitgitgadget:master
from
phillipwood:sequencer-parsing-fixes
Closed
sequencer parsing fixes #1486
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2479,12 +2479,11 @@ static int is_command(enum todo_command command, const char **bol) | |
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jeff King wrote (reply to this): On Thu, Feb 23, 2023 at 08:55:00PM +0000, Phillip Wood via GitGitGadget wrote:
> Fix this by ensuring the match is follow by whitespace or the end of the
> string as we already do for abbreviated commands. The (*bol = p) at the
> end of the condition is a bit cute for my taste but I decided to leave
> it be for now. Rather than add new tests the existing tests for bad
> commands are adapted to use a bad command name that triggers the prefix
> matching bug.
FWIW, coverity complained about the (*bol = p) assignment in the
conditional, since "p" must be non-NULL at this point.
So this is email is a combination of:
- a data point that it is not just you that finds it a bit cute (in
case you do want to change it later); and
- a hearty thank you for mentioning it in the commit message, since
just looking at the code left me scratching my head at whether this
was a bug.
-Peff |
||
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 parse_insn_line(struct repository *r, struct todo_item *item, | ||
|
@@ -2513,7 +2512,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, | |
break; | ||
} | ||
if (i >= TODO_COMMENT) | ||
return -1; | ||
return error(_("invalid command '%.*s'"), | ||
(int)strcspn(bol, " \t\r\n"), bol); | ||
|
||
/* Eat up extra spaces/ tabs before object name */ | ||
padding = strspn(bol, " \t"); | ||
|
@@ -2542,12 +2542,10 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, | |
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
> if (item->command == TODO_FIXUP) {
> - if (skip_prefix(bol, "-C", &bol) &&
> - (*bol == ' ' || *bol == '\t')) {
> + if (skip_prefix(bol, "-C", &bol)) {
> bol += strspn(bol, " \t");
> item->flags |= TODO_REPLACE_FIXUP_MSG;
OK. An explicit check followed by strspn() is an odd way to write
this even if it meant to require at least one whitespace, but I
agree that this one probably did not even mean to require a
whitespace there, and the updated code looks much easier to read.
> diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
> index 1d2f0429aea..7ca5b918f04 100644
> --- a/t/lib-rebase.sh
> +++ b/t/lib-rebase.sh
> ...
> +test_expect_success 'fixup -[Cc]<commit> works' '
> + test_when_finished "test_might_fail git rebase --abort" &&
> + cat >todo <<-\EOF &&
> + pick A
> + fixup -CA1
> + pick B
> + fixup -cA2
> + EOF
By the way, this is much easier to follow, than the todo file written
in the ugly FAKE_LINES language, to see what is being tested.
Will queue. Thanks. |
||
|
||
if (item->command == TODO_FIXUP) { | ||
if (skip_prefix(bol, "-C", &bol) && | ||
(*bol == ' ' || *bol == '\t')) { | ||
if (skip_prefix(bol, "-C", &bol)) { | ||
bol += strspn(bol, " \t"); | ||
item->flags |= TODO_REPLACE_FIXUP_MSG; | ||
} else if (skip_prefix(bol, "-c", &bol) && | ||
(*bol == ' ' || *bol == '\t')) { | ||
} else if (skip_prefix(bol, "-c", &bol)) { | ||
bol += strspn(bol, " \t"); | ||
item->flags |= TODO_EDIT_FIXUP_MSG; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Junio C Hamano wrote (reply to this):