-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Git diff coloring #11590
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
Git diff coloring #11590
Conversation
ada71da
to
e19be0c
Compare
@@ -242,7 +242,7 @@ public interface IGitModule | |||
/// <param name="cancellationToken">A cancellation token.</param> | |||
/// <returns>the Git output.</returns> | |||
string GetCustomDiffMergeTools(bool isDiff, CancellationToken cancellationToken); | |||
Task<(Patch? patch, string? errorMessage)> GetSingleDiffAsync(ObjectId? firstId, ObjectId? secondId, string? fileName, string? oldFileName, string extraDiffArguments, Encoding encoding, bool cacheResult, bool isTracked, CancellationToken cancellationToken); | |||
Task<(Patch? patch, string? errorMessage)> GetSingleDiffAsync(ObjectId? firstId, ObjectId? secondId, string? fileName, string? oldFileName, string extraDiffArguments, Encoding encoding, bool cacheResult, bool isTracked, bool useGitColoring, GitCommandConfiguration commandConfiguration, CancellationToken cancellationToken); | |||
int? GetCommitCount(string parent, string child, bool cache, bool throwOnErrorExit); |
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.
These API were already long and now they are bordering on "gross" long... We'll need to revisit these.
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.
LGTM, few minor comments and nits
GitUI/CommandsDialogs/SettingsDialog/Pages/ColorsSettings/ColorsSettingsPage.cs
Outdated
Show resolved
Hide resolved
GitUI/Translation/English.xlf
Outdated
@@ -1598,6 +1614,10 @@ The primary difftool can still be selected by clicking the main menu entry.</sou | |||
<source>Show &entire file</source> | |||
<target /> | |||
</trans-unit> | |||
<trans-unit id="showGitWordColoringToolStripMenuItem.Text"> | |||
<source>Show Git word coloring</source> |
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.
The assigned hotkey should be displayed in the menu item.
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.
It is shown
Setting accelerator to D
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.
It is shown
👍 (In other files, the regarding lines are not that spread over the files as here. So, I missed the already existing line.)
Setting accelerator to D
Then double use of D: for "&Decrease the number of lines of context"
@mstv Can I squash and rebase (as in tmp/git-coloring)? |
ed1ad2d
to
511b00f
Compare
511b00f
to
8f0cf1e
Compare
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.
have not tested in detail
bb68c11
to
578837e
Compare
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.
2 tests fail (due to difference in linebreak?)
@RussKie any comments on the tests or anything else? |
With Git word diff, there is no notion about changed lines in the Git output. I probably miss the markers on the line numbers more, not sure how to guess. First or last color on line? most dominant color? rainbow? I have not thought about this in detail, would like to get this and git-diff "ready" before I divert again. Maybe using Delta viewer as an alternative is a step forward (with even more limitations in navigating and copying). For git-word-diff, it is probably easier to modify Git directly than to patch the output. I almost got it working guessing how to convert back to word format.
Even harder, then you need to know what the change is and set unique color codes for old/new that are weird or check all Git colors so they are not used for other purposes too. |
exactly
Would be good in a follow-up.
' ', '+', '-', '~'
acceptable |
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.
Missing features which require heuristics could be added in follow-ups.
@mstv See tmp/git-coloring 5cae497 @RussKie Any comments on the tests, I would like to proceed with this and the dependent git-grep PR |
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.
🚀
Enable Git word diff coloring view. This is an alternative view for diff, not in patch format. The differences are coded on the same line.
f8fbb2a
to
7e2c953
Compare
Let's merge this now and separately review e7b1fd3. |
Move handling of "normal" patches from the shared DiffHighlightService to PatchHighlightService. File-structure namespaces. Various code cleanups. This commit is a preparation for Git coloring and git-grep.
Use the coloring by git-diff instead of GE internal algorithm, by using Git ANSI terminal escape sequences. This enables for instance view moved code.
Enable Git word diff coloring view. This is an alternative view for diff, not in patch format. The differences are coded on the same line.
7e2c953
to
4c0d640
Compare
as well as range-diff and git-grep. git coloring of command output was added in gitextensions#11590. The patch view (default) is configurable, keeping the current GE coloring if a user prefers. This removes the GE coloring for some commands ans the GE coloring is very limited and adding to the complexity. * git-word-diff (gitextensions#11590) * git-grep (gitextensions#11359) * git-range-diff (very limited GE coloring).
as well as range-diff and git-grep. Use of Git coloring of command output was added in gitextensions#11590. The patch view (default) is configurable, setting to keep the current GE coloring. This removes the GE coloring for some commands ans the GE coloring is very limited and is adding complexity. * git-word-diff (gitextensions#11590) * git-grep (gitextensions#11359) * git-range-diff (very limited GE coloring).
as well as range-diff and git-grep. Use of Git coloring of command output was added in gitextensions#11590. The patch view (default) is configurable, setting to keep the current GE coloring. This removes the GE coloring for some commands ans the GE coloring is very limited and is adding complexity. * git-word-diff (gitextensions#11590) * git-grep (gitextensions#11359) * git-range-diff (very limited GE coloring).
as well as range-diff and git-grep. Use of Git coloring of command output was added in #11590. The patch view (default) is configurable, setting to keep the current GE coloring. This removes the GE coloring for some commands ans the GE coloring is very limited and is adding complexity. * git-word-diff (#11590) * git-grep (#11359) * git-range-diff (very limited GE coloring).
Fixes #11464
Fixes #11517
Proposed changes
TBD, opened to get feedback.
Description will be improved too, as well as screenshots.
--
FileViewer: Restructure HighlightService
Move handling of "normal" patches from the shared
DiffHighlightService to PatchHighlightService.
Various code cleanups.
This commit is a preparation for Git coloring and git-grep.
--
Git diff coloring
Use the coloring by git-diff instead of GE internal algorithm,
by using Git ANSI terminal escape sequences.
This enables for instance view moved code.
Configuration: Git coloring is set by default, the existing engine is still available.
The GE theme colors for added/removed code (reverse green/red) is applied by default (default Git to just set foreground text is can be configured).
Git by default warns about white space, this is disabled by default (diff.colorMovedWS).
A user can override the Git colors for each "slot" (see below), but this is not available in GE UI.
--
Git word diff coloring
Enable Git word diff coloring view.
This is an alternative view for diff, not in patch format.
The differences are coded on the same line.
Configuration: "GE word highlighting" is the default, "Git diff highlighting" can be enabled.
By default Git highlights changed words. If the user has not set diff.wordRegex, change by character is used ('.').
--
What is not in this PR:
Screenshots
TBD, see #11464 for now
moved
The third is "Git default", no GE theme override, whitespace errors

range diff - the GE coloring is very limited
A missed merge (color should have been yellow, I have modified it). Dual color makes these diffs easier to read.

Git word diff
The word diff is best used to toggle the view back and forward to see details, only worddiff is confusing
ANSI Color theme
Git uses "slots" like old, new, oldMoved etc to set situations.
https://git-scm.com/docs/git-config#Documentation/git-config.txt-colordiffltslotgt
The slots are translated to named colors (8) that can be normal/bright/dim (and more, not really used in Git) as well as background/foreground. A terminal uses a "theme" to translate these colors.
The "theme" for these colors in this PR is displayed below as well as the GE theme colors overriding the default. (Note that the GE colors DiffAddedExtra and DiffRemovedExtra has no direct fit in the ANSI colors, maybe bright is the closest).
Test methodology
Manual, tests to be added, maybe in a followup PR
Merge strategy
✒️ I contribute this code under The Developer Certificate of Origin.