From aec498e9b0bebcf363ee166237f4b41ea196b9f1 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 27 Oct 2022 22:11:24 +0800 Subject: [PATCH] optimize: do not re-diff when file not changed --- src/Views/Widgets/Dashboard.xaml.cs | 3 --- src/Views/Widgets/DiffViewer.xaml | 4 +-- src/Views/Widgets/DiffViewer.xaml.cs | 39 ++++++++++++++++++--------- src/Views/Widgets/WorkingCopy.xaml.cs | 26 ++++++++++++------ 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs index 85bae5ec..74bf0d53 100644 --- a/src/Views/Widgets/Dashboard.xaml.cs +++ b/src/Views/Widgets/Dashboard.xaml.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; -using System.Net.Sockets; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -12,7 +10,6 @@ using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; -using System.Xml.Linq; namespace SourceGit.Views.Widgets { diff --git a/src/Views/Widgets/DiffViewer.xaml b/src/Views/Widgets/DiffViewer.xaml index 34666476..b0a801d7 100644 --- a/src/Views/Widgets/DiffViewer.xaml +++ b/src/Views/Widgets/DiffViewer.xaml @@ -16,7 +16,7 @@ - + @@ -50,7 +50,7 @@ Icon="{StaticResource Icon.Down}" ToolTip="{DynamicResource Text.Diff.Next}" Click="GotoNextChange"/> - + cachedTextChanges = null; private List editors = new List(); private List splitters = new List(); + private string lastWCFileId = ""; public DiffViewer() { InitializeComponent(); @@ -51,6 +53,8 @@ namespace SourceGit.Views.Widgets { toolbar.Visibility = Visibility.Collapsed; noChange.Visibility = Visibility.Collapsed; sizeChange.Visibility = Visibility.Collapsed; + textDiff.Visibility = Visibility.Collapsed; + lastWCFileId = ""; ClearCache(); foreach (var e in editors) e.ItemsSource = null; @@ -58,15 +62,27 @@ namespace SourceGit.Views.Widgets { } public void Diff(string repo, Option opt) { - seq++; + if (opt.WCChanges) { + var fileInfo = new System.IO.FileInfo(repo + "/" + opt.Path); + if (fileInfo.Exists) { + var wcFileID = string.Format("{0}@{1}", opt.Path, fileInfo.LastWriteTime.ToFileTime()); + if (wcFileID == lastWCFileId) return; + lastWCFileId = wcFileID; + } else { + lastWCFileId = ""; + } + } else { + lastWCFileId = ""; + } - foreach (var e in editors) e.ItemsSource = null; - foreach (var s in splitters) s.Visibility = Visibility.Hidden; + seq++; ClearCache(); mask.Visibility = Visibility.Collapsed; noChange.Visibility = Visibility.Collapsed; sizeChange.Visibility = Visibility.Collapsed; + toolbarOptions.Visibility = Visibility.Collapsed; + textDiff.Visibility = Visibility.Collapsed; toolbar.Visibility = Visibility.Visible; loading.Visibility = Visibility.Visible; loading.IsAnimating = true; @@ -140,7 +156,6 @@ namespace SourceGit.Views.Widgets { loading.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed; - toolbarOptions.Visibility = Visibility.Collapsed; sizeChange.Visibility = Visibility.Visible; txtSizeChangeTitle.Text = App.Text("Diff.Binary"); @@ -159,7 +174,6 @@ namespace SourceGit.Views.Widgets { loading.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed; - toolbarOptions.Visibility = Visibility.Collapsed; sizeChange.Visibility = Visibility.Visible; txtSizeChangeTitle.Text = App.Text("Diff.LFS"); @@ -175,7 +189,6 @@ namespace SourceGit.Views.Widgets { loading.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed; - toolbarOptions.Visibility = Visibility.Collapsed; noChange.Visibility = Visibility.Visible; }); } @@ -207,11 +220,12 @@ namespace SourceGit.Views.Widgets { loading.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed; toolbarOptions.Visibility = Visibility.Visible; + textDiff.Visibility = Visibility.Visible; var createEditor = editors.Count == 0; var lineNumberWidth = CalcLineNumberColWidth(lastOldLine, lastNewLine); - var minWidth = textDiff.ActualWidth - lineNumberWidth * 2; - if (textDiff.ActualHeight < cachedTextChanges.Count * 16) minWidth -= 8; + var minWidth = body.ActualWidth - lineNumberWidth * 2; + if (body.ActualHeight - 26 < cachedTextChanges.Count * 16) minWidth -= 8; DataGrid editor; if (createEditor) { @@ -272,11 +286,12 @@ namespace SourceGit.Views.Widgets { loading.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed; toolbarOptions.Visibility = Visibility.Visible; + textDiff.Visibility = Visibility.Visible; var createEditor = editors.Count == 0; var lineNumberWidth = CalcLineNumberColWidth(lastOldLine, lastNewLine); - var minWidth = textDiff.ActualWidth / 2 - lineNumberWidth; - if (textDiff.ActualHeight < newSideBlocks.Count * 16) minWidth -= 8; + var minWidth = body.ActualWidth / 2 - lineNumberWidth; + if (body.ActualHeight - 26 < newSideBlocks.Count * 16) minWidth -= 8; DataGrid oldEditor, newEditor; if (createEditor) { @@ -441,11 +456,11 @@ namespace SourceGit.Views.Widgets { private void OnTextDiffSizeChanged(object sender, SizeChangedEventArgs e) { if (editors.Count == 0) return; - var total = textDiff.ActualWidth / editors.Count; + var total = body.ActualWidth / editors.Count; for (int i = 0; i < editors.Count; i++) { var editor = editors[i]; var minWidth = total - editor.NonFrozenColumnsViewportHorizontalOffset; - if (editor.Items.Count * 16 > textDiff.ActualHeight) minWidth -= 8; + if (editor.Items.Count * 16 > body.ActualHeight - 26) minWidth -= 8; var lastColumn = editor.Columns.Count - 1; editor.Columns[lastColumn].MinWidth = minWidth; diff --git a/src/Views/Widgets/WorkingCopy.xaml.cs b/src/Views/Widgets/WorkingCopy.xaml.cs index 6d632609..78c2be41 100644 --- a/src/Views/Widgets/WorkingCopy.xaml.cs +++ b/src/Views/Widgets/WorkingCopy.xaml.cs @@ -53,16 +53,24 @@ namespace SourceGit.Views.Widgets { btnCommitAndPush.Visibility = Visibility.Collapsed; } + mergePanel.Visibility = Visibility.Collapsed; + var diffTarget = unstagedContainer.DiffTarget; - if (diffTarget == null) diffTarget = stagedContainer.DiffTarget; + if (diffTarget != null) { + if (diffTarget.IsConflit) { + mergePanel.Visibility = Visibility.Visible; + diffViewer.Reset(); + } else { + diffViewer.Reload(); + } + + return; + } + + diffTarget = stagedContainer.DiffTarget; if (diffTarget == null) { - mergePanel.Visibility = Visibility.Collapsed; - diffViewer.Reset(); - } else if (diffTarget.IsConflit) { - mergePanel.Visibility = Visibility.Visible; diffViewer.Reset(); } else { - mergePanel.Visibility = Visibility.Collapsed; diffViewer.Reload(); } } @@ -145,14 +153,16 @@ namespace SourceGit.Views.Widgets { ExtraArgs = "--no-index", Path = change.Path, OrgPath = "/dev/null", - UseLFS = isLFSEnabled + UseLFS = isLFSEnabled, + WCChanges = true, }); break; default: diffViewer.Diff(repo.Path, new DiffViewer.Option() { Path = change.Path, OrgPath = change.OriginalPath, - UseLFS = isLFSEnabled + UseLFS = isLFSEnabled, + WCChanges = true, }); break; }