mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-22 02:45:00 +00:00
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:
parent
cd5a682194
commit
17f94e8228
4 changed files with 48 additions and 3 deletions
|
@ -28,9 +28,9 @@ namespace SourceGit.Commands
|
||||||
Context = repo;
|
Context = repo;
|
||||||
|
|
||||||
if (ignoreWhitespace)
|
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
|
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()
|
public Models.DiffResult Result()
|
||||||
|
|
|
@ -656,6 +656,7 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
public class NoOrEOLChange
|
public class NoOrEOLChange
|
||||||
{
|
{
|
||||||
|
// The empty class is kept for backward compatibility
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FileModeDiff
|
public class FileModeDiff
|
||||||
|
|
|
@ -207,7 +207,50 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else
|
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(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
|
|
@ -745,6 +745,7 @@ namespace SourceGit.Views
|
||||||
var val = ShowHiddenSymbols;
|
var val = ShowHiddenSymbols;
|
||||||
Options.ShowTabs = val;
|
Options.ShowTabs = val;
|
||||||
Options.ShowSpaces = val;
|
Options.ShowSpaces = val;
|
||||||
|
Options.ShowEndOfLine = val;
|
||||||
}
|
}
|
||||||
else if (change.Property == TabWidthProperty)
|
else if (change.Property == TabWidthProperty)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue