Skip to content

Conversation

gerhardol
Copy link
Member

Proposed changes

Tune the heuristics to get word-diff line numbers. If the diff only had added or removed chars, only added/removed line numbers were presented.

There are still many situations where the Git output is incomplete, the line numbers will be incorrect still.
Comments added to the code, trying to explain the issues.

Screenshots

File to compare is in a private branch, did not find a good example in recent commits

image

with #11868

image

Before

see line 20

image

After

image

Test methodology

tests updated

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

Tune the heuristics to get word-diff line numbers.
If the diff only had added or removed chars, only added/removed
line numbers were presented.

There are still many situations where the Git output is incomplete,
the line numbers will be incorrect still.
Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first chosen example "23 22 SetText(ref text);" seems to be one of "the line numbers will be incorrect still." (not requesting a change)

Off topic:
The base commit also crashes when trying to display word diff of tests/app/UnitTests/GitUI.Tests/Editor/Diff/SampleGitWord.diff.

Comment on lines 182 to 188
return lineType is (DiffLineType.Minus or DiffLineType.MinusLeft)
? (AppSettings.ReverseGitColoring.Value
? textMarker.Color == AppColor.AnsiTerminalRedBackNormal.GetThemeColor()
: textMarker.ForeColor == AppColor.AnsiTerminalRedForeNormal.GetThemeColor())
: (AppSettings.ReverseGitColoring.Value
? textMarker.Color == AppColor.AnsiTerminalGreenBackNormal.GetThemeColor()
: textMarker.ForeColor == AppColor.AnsiTerminalGreenForeNormal.GetThemeColor());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider reading AppSettings.ReverseGitColoring.Value at most once per document.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the cost? This is used in other parts too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar could be done in the Difftastic highlighter, other seem OK

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~1000-4000 settings evaluations take 1 ms. This can add up.

Copy link
Contributor

@vbjay vbjay Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache at begining of process. Store colors in something like a dictionary of some key and the color value. Just make sure dictionary is reloaded if settings change or even if new analyzer created. Maybe even provide a function in AppColor that generates this dictionary.

@gerhardol
Copy link
Member Author

My first chosen example "23 22 SetText(ref text);" seems to be one of "the line numbers will be incorrect still." (not requesting a change)

That is the Git output, not much can be done.
Your diff is often more useful.

The base commit also crashes when trying to display word diff

Noticed that too, have not investigated

@gerhardol gerhardol force-pushed the feature/git-word-diff-lineno branch from 8edae43 to 6b749dc Compare September 9, 2024 20:29
@gerhardol gerhardol merged commit 674a227 into gitextensions:master Sep 9, 2024
3 of 4 checks passed
@gerhardol gerhardol deleted the feature/git-word-diff-lineno branch September 9, 2024 21:07
@RussKie RussKie added this to the 5.1 milestone Nov 6, 2024
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.

4 participants