refactor: improve diff handling for EOL changes and enhance text diff 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.
This commit is contained in:
mpagani 2025-04-11 17:32:37 +02:00
parent cd5a682194
commit 17f94e8228
4 changed files with 48 additions and 3 deletions

View file

@ -28,9 +28,9 @@ namespace SourceGit.Commands
Context = repo;
if (ignoreWhitespace)
Args = $"-c core.autocrlf=false diff --no-ext-diff --patch --ignore-cr-at-eol --ignore-all-space --unified={unified} {opt}";
Args = $"-c core.autocrlf=false diff --no-ext-diff --patch --ignore-all-space --unified={unified} {opt}";
else
Args = $"-c core.autocrlf=false diff --no-ext-diff --patch --ignore-cr-at-eol --unified={unified} {opt}";
Args = $"-c core.autocrlf=false diff --no-ext-diff --patch --unified={unified} {opt}";
}
public Models.DiffResult Result()

View file

@ -656,6 +656,7 @@ namespace SourceGit.Models
public class NoOrEOLChange
{
// The empty class is kept for backward compatibility
}
public class FileModeDiff

View file

@ -207,7 +207,50 @@ namespace SourceGit.ViewModels
}
else
{
rs = new Models.NoOrEOLChange();
// Check if old and new hashes differ but no text changes found
if (!string.IsNullOrEmpty(latest.OldHash) &&
!string.IsNullOrEmpty(latest.NewHash) &&
latest.OldHash != latest.NewHash)
{
// If hashes differ but no text diff found, it's likely an EOL change
// Create a text diff to show the file content
var textDiff = new Models.TextDiff()
{
Repo = _repo,
Option = _option,
File = _option.Path
};
// Query the file content to show
var fileContent = Commands.QueryFileContent.Run(_repo, "HEAD", _option.Path);
using var reader = new StreamReader(fileContent);
var line = string.Empty;
int lineNumber = 1;
while ((line = reader.ReadLine()) != null)
{
textDiff.Lines.Add(new Models.TextDiffLine(
Models.TextDiffLineType.Normal,
line,
lineNumber,
lineNumber));
lineNumber++;
}
if (textDiff.Lines.Count > 0)
{
textDiff.MaxLineNumber = lineNumber - 1;
rs = textDiff;
}
else
{
rs = new Models.NoOrEOLChange();
}
}
else
{
rs = new Models.NoOrEOLChange();
}
}
Dispatcher.UIThread.Post(() =>

View file

@ -745,6 +745,7 @@ namespace SourceGit.Views
var val = ShowHiddenSymbols;
Options.ShowTabs = val;
Options.ShowSpaces = val;
Options.ShowEndOfLine = val;
}
else if (change.Property == TabWidthProperty)
{