Skip to content
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

Rewrite diff syntax highlighter #466

Merged
merged 1 commit into from Jun 16, 2015

Conversation

living180
Copy link
Contributor

The previous DiffSyntaxHighlighter worked adequately, but because it was stateless, it needed a lot of complicated regular expressions to try to match all the possible diff header lines. It could also be thrown off, if for example a line was removed starting with '-- ', the resulting diff line would start with '--- ', causing the syntax highlighter to interpret it as a header line instead of a removal. To address these shortcomings, completely rewrite the syntax highlighter to be stateful. This greatly simplifies the logic and drastically reduces the number of regular expressions that need to be matched. Because DiffSyntaxHighlighter was the only user of GenericSyntaxHighlighter, and GenericSyntaxHighlighter does not fit the stateful approach, eliminate GenericSyntaxHighlighter (moving a few necessary bits to DiffSyntaxHighlighter) and move DiffSyntaxHighlighter from qtutils to widgets.diff, where it is actually used.

Closes #462.

The previous DiffSyntaxHighlighter worked adequately, but because it was
stateless, it needed a lot of complicated regular expressions to try to
match all the possible diff header lines.  It could also be thrown off,
if for example a line was removed starting with '-- ', the resulting
diff line would start with '--- ', causing the syntax highlighter to
interpret it as a header line instead of a removal.  To address these
shortcomings, completely rewrite the syntax highlighter to be stateful.
This greatly simplifies the logic and drastically reduces the number of
regular expressions that need to be matched.  Because
DiffSyntaxHighlighter was the only user of GenericSyntaxHighlighter, and
GenericSyntaxHighlighter does not fit the stateful approach, eliminate
GenericSyntaxHighlighter (moving a few necessary bits to
DiffSyntaxHighlighter) and move DiffSyntaxHighlighter from qtutils to
widgets.diff, where it is actually used.

Closes git-cola#462
Reported-by: Andreas Sommer <andreas.sommer87@googlemail.com>
Signed-off-by: Daniel Harding <dharding@living180.net>
@davvid
Copy link
Member

davvid commented Jun 16, 2015

Nicely done. 👏

davvid added a commit that referenced this pull request Jun 16, 2015
diff: rewrite diff syntax highlighter

Signed-off-by: David Aguilar <davvid@gmail.com>
@davvid davvid merged commit d847f98 into git-cola:master Jun 16, 2015
@living180 living180 deleted the new_diff_syntax_highlighter branch June 16, 2015 08:08
@AndiDog
Copy link
Contributor

AndiDog commented Jun 16, 2015

Changed/new commits in submodules are now gray text instead of black. Intended?

@living180
Copy link
Contributor Author

No, I intended to preserve pre-existing behavior (modulo an additional bug I found in the old code). I'll try to look at what is going on this week to see about getting a fix in. Thanks for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants