Adjusted params for the new GetDiffObject() method

This commit is contained in:
Henrik Andersson 2025-06-04 10:40:25 +02:00
parent 0cc565d193
commit 33470eda19

View file

@ -145,7 +145,7 @@ namespace SourceGit.ViewModels
_info = info; _info = info;
var rs = GetDiffObject(latest); var rs = GetDiffObject(latest, _option);
Dispatcher.UIThread.Post(() => Dispatcher.UIThread.Post(() =>
{ {
@ -160,21 +160,21 @@ namespace SourceGit.ViewModels
}); });
} }
private object GetDiffObject(DiffResult latest) private object GetDiffObject(DiffResult diffResult, DiffOption diffOption)
{ {
var rs = null as object; var rs = null as object;
if (latest.TextDiff != null) if (diffResult.TextDiff != null)
{ {
var count = latest.TextDiff.Lines.Count; var count = diffResult.TextDiff.Lines.Count;
var isSubmodule = false; var isSubmodule = false;
if (count <= 3) if (count <= 3)
{ {
var submoduleDiff = new Models.SubmoduleDiff(); var submoduleDiff = new Models.SubmoduleDiff();
var submoduleRoot = $"{_repo}/{_option.Path}".Replace("\\", "/"); var submoduleRoot = $"{_repo}/{diffOption.Path}".Replace("\\", "/");
isSubmodule = true; isSubmodule = true;
for (int i = 1; i < count; i++) for (int i = 1; i < count; i++)
{ {
var line = latest.TextDiff.Lines[i]; var line = diffResult.TextDiff.Lines[i];
if (!line.Content.StartsWith("Subproject commit ", StringComparison.Ordinal)) if (!line.Content.StartsWith("Subproject commit ", StringComparison.Ordinal))
{ {
isSubmodule = false; isSubmodule = false;
@ -194,29 +194,29 @@ namespace SourceGit.ViewModels
if (!isSubmodule) if (!isSubmodule)
{ {
latest.TextDiff.File = _option.Path; diffResult.TextDiff.File = diffOption.Path;
rs = latest.TextDiff; rs = diffResult.TextDiff;
} }
} }
else if (latest.IsBinary) else if (diffResult.IsBinary)
{ {
var oldPath = string.IsNullOrEmpty(_option.OrgPath) ? _option.Path : _option.OrgPath; var oldPath = string.IsNullOrEmpty(diffOption.OrgPath) ? diffOption.Path : diffOption.OrgPath;
var ext = Path.GetExtension(_option.Path); var ext = Path.GetExtension(diffOption.Path);
if (IMG_EXTS.Contains(ext)) if (IMG_EXTS.Contains(ext))
{ {
var imgDiff = new Models.ImageDiff(); var imgDiff = new Models.ImageDiff();
if (_option.Revisions.Count == 2) if (diffOption.Revisions.Count == 2)
{ {
(imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[0], oldPath); (imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, diffOption.Revisions[0], oldPath);
(imgDiff.New, imgDiff.NewFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[1], _option.Path); (imgDiff.New, imgDiff.NewFileSize) = BitmapFromRevisionFile(_repo, diffOption.Revisions[1], diffOption.Path);
} }
else else
{ {
if (!oldPath.Equals("/dev/null", StringComparison.Ordinal)) if (!oldPath.Equals("/dev/null", StringComparison.Ordinal))
(imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, "HEAD", oldPath); (imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, "HEAD", oldPath);
var fullPath = Path.Combine(_repo, _option.Path); var fullPath = Path.Combine(_repo, diffOption.Path);
if (File.Exists(fullPath)) if (File.Exists(fullPath))
{ {
imgDiff.New = new Bitmap(fullPath); imgDiff.New = new Bitmap(fullPath);
@ -228,23 +228,23 @@ namespace SourceGit.ViewModels
else else
{ {
var binaryDiff = new Models.BinaryDiff(); var binaryDiff = new Models.BinaryDiff();
if (_option.Revisions.Count == 2) if (diffOption.Revisions.Count == 2)
{ {
binaryDiff.OldSize = new Commands.QueryFileSize(_repo, oldPath, _option.Revisions[0]).Result(); binaryDiff.OldSize = new Commands.QueryFileSize(_repo, oldPath, diffOption.Revisions[0]).Result();
binaryDiff.NewSize = new Commands.QueryFileSize(_repo, _option.Path, _option.Revisions[1]).Result(); binaryDiff.NewSize = new Commands.QueryFileSize(_repo, diffOption.Path, diffOption.Revisions[1]).Result();
} }
else else
{ {
var fullPath = Path.Combine(_repo, _option.Path); var fullPath = Path.Combine(_repo, diffOption.Path);
binaryDiff.OldSize = new Commands.QueryFileSize(_repo, oldPath, "HEAD").Result(); binaryDiff.OldSize = new Commands.QueryFileSize(_repo, oldPath, "HEAD").Result();
binaryDiff.NewSize = File.Exists(fullPath) ? new FileInfo(fullPath).Length : 0; binaryDiff.NewSize = File.Exists(fullPath) ? new FileInfo(fullPath).Length : 0;
} }
rs = binaryDiff; rs = binaryDiff;
} }
} }
else if (latest.IsLFS) else if (diffResult.IsLFS)
{ {
rs = latest.LFSDiff; rs = diffResult.LFSDiff;
} }
else else
{ {