Skip to content

refactor: improve diff handling for EOL changes and enhance text diff… #1177

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

Merged
merged 5 commits into from
Apr 14, 2025

Conversation

massimopaganigh
Copy link
Contributor

… display

  • Updated Diff.cs to streamline whitespace handling in diff arguments.
  • Enhanced DiffContext.cs to check for EOL changes when old and new hashes differ, creating a text diff if necessary.
  • Added support for showing end-of-line symbols in TextDiffView.axaml.cs options.

mpagani and others added 2 commits April 11, 2025 17:32
… display

- Updated `Diff.cs` to streamline whitespace handling in diff arguments.
- Enhanced `DiffContext.cs` to check for EOL changes when old and new hashes differ, creating a text diff if necessary.
- Added support for showing end-of-line symbols in `TextDiffView.axaml.cs` options.
…hitespace messages

- Modified the ignore whitespace text in multiple language files to specify that EOF changes are also ignored.
- Ensured consistency across all localization files for the patch application feature.
@massimopaganigh
Copy link
Contributor Author

I thought about implementing these changes because I often commit without realising that I have inadvertently changed all the EOFs. I was inspired by what Git Extensions does, which is to report EOFs as changes if you choose to show whitespace.

P.S.
I had some help with the translations, but still checked that the changes made sense, so I apologise to the translators in advance if I made any mistakes.

@love-linger
Copy link
Collaborator

Please remove the changes about Text.Apply.IgnoreWS translations. It's not used by diff viewer.

@massimopaganigh
Copy link
Contributor Author

Please remove the changes about Text.Apply.IgnoreWS translations. It's not used by diff viewer.

Alright

@love-linger love-linger self-assigned this Apr 14, 2025
@love-linger love-linger added the enhancement New feature or request label Apr 14, 2025
…noreWS and fixed typo in Text.Diff.IgnoreWhitespace (EOF => EOL)
@love-linger love-linger merged commit 81820e7 into sourcegit-scm:develop Apr 14, 2025
13 checks passed
love-linger added a commit that referenced this pull request Apr 14, 2025
- use `Command.ReadToEnd` instead of `Command.Exec` to avoid git trims line endings.
- use `StringBuilder.Append('\n')` instead of `StringBuilder.AppendLine()` to restore original line endings (we split the original diff output by `\n` not `\r')
- there's no need to show file content (the `StreamReader.ReadLine()` will trim line endings)

Signed-off-by: leo <[email protected]>
@love-linger
Copy link
Collaborator

love-linger commented Apr 21, 2025

Since some people have reported that they are not used to the new EOL processing way, and some commonly used tools such as Github and Fork also enable --ignore-cr-at-eol by default, this PR will be reverted in the next version.

love-linger added a commit that referenced this pull request Apr 21, 2025
Signed-off-by: leo <[email protected]>
@love-linger
Copy link
Collaborator

love-linger commented Apr 21, 2025

Another reason is that Options.ShowEndOfLine = true shows the line-endings in the diff command output, and may not be the line-endings of the original file.

For example, if there is no empty line at the end of the file before the change, the diff result will have an extra line \ No newline at end of file. This causes the last line of the original file to have an extra line-ending.

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

Successfully merging this pull request may close these issues.

2 participants