optimize<WorkingCopy>: do not re-diff when file not changed

This commit is contained in:
leo 2022-10-27 22:11:24 +08:00
parent 87d96598be
commit aec498e9b0
4 changed files with 47 additions and 25 deletions

View file

@ -1,10 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Sockets;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -12,7 +10,6 @@ using System.Windows.Controls.Primitives;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Xml.Linq;
namespace SourceGit.Views.Widgets { namespace SourceGit.Views.Widgets {

View file

@ -16,7 +16,7 @@
</UserControl.Resources> </UserControl.Resources>
<Border BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1"> <Border BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1">
<Grid> <Grid x:Name="body">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="26"/> <RowDefinition Height="26"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>

View file

@ -23,6 +23,7 @@ namespace SourceGit.Views.Widgets {
public string OrgPath = null; public string OrgPath = null;
public string ExtraArgs = ""; public string ExtraArgs = "";
public bool UseLFS = false; public bool UseLFS = false;
public bool WCChanges = false;
} }
private ulong seq = 0; private ulong seq = 0;
@ -31,6 +32,7 @@ namespace SourceGit.Views.Widgets {
private List<Models.TextChanges.Line> cachedTextChanges = null; private List<Models.TextChanges.Line> cachedTextChanges = null;
private List<DataGrid> editors = new List<DataGrid>(); private List<DataGrid> editors = new List<DataGrid>();
private List<Rectangle> splitters = new List<Rectangle>(); private List<Rectangle> splitters = new List<Rectangle>();
private string lastWCFileId = "";
public DiffViewer() { public DiffViewer() {
InitializeComponent(); InitializeComponent();
@ -51,6 +53,8 @@ namespace SourceGit.Views.Widgets {
toolbar.Visibility = Visibility.Collapsed; toolbar.Visibility = Visibility.Collapsed;
noChange.Visibility = Visibility.Collapsed; noChange.Visibility = Visibility.Collapsed;
sizeChange.Visibility = Visibility.Collapsed; sizeChange.Visibility = Visibility.Collapsed;
textDiff.Visibility = Visibility.Collapsed;
lastWCFileId = "";
ClearCache(); ClearCache();
foreach (var e in editors) e.ItemsSource = null; foreach (var e in editors) e.ItemsSource = null;
@ -58,15 +62,27 @@ namespace SourceGit.Views.Widgets {
} }
public void Diff(string repo, Option opt) { 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; seq++;
foreach (var s in splitters) s.Visibility = Visibility.Hidden;
ClearCache(); ClearCache();
mask.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed;
noChange.Visibility = Visibility.Collapsed; noChange.Visibility = Visibility.Collapsed;
sizeChange.Visibility = Visibility.Collapsed; sizeChange.Visibility = Visibility.Collapsed;
toolbarOptions.Visibility = Visibility.Collapsed;
textDiff.Visibility = Visibility.Collapsed;
toolbar.Visibility = Visibility.Visible; toolbar.Visibility = Visibility.Visible;
loading.Visibility = Visibility.Visible; loading.Visibility = Visibility.Visible;
loading.IsAnimating = true; loading.IsAnimating = true;
@ -140,7 +156,6 @@ namespace SourceGit.Views.Widgets {
loading.Visibility = Visibility.Collapsed; loading.Visibility = Visibility.Collapsed;
mask.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed;
toolbarOptions.Visibility = Visibility.Collapsed;
sizeChange.Visibility = Visibility.Visible; sizeChange.Visibility = Visibility.Visible;
txtSizeChangeTitle.Text = App.Text("Diff.Binary"); txtSizeChangeTitle.Text = App.Text("Diff.Binary");
@ -159,7 +174,6 @@ namespace SourceGit.Views.Widgets {
loading.Visibility = Visibility.Collapsed; loading.Visibility = Visibility.Collapsed;
mask.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed;
toolbarOptions.Visibility = Visibility.Collapsed;
sizeChange.Visibility = Visibility.Visible; sizeChange.Visibility = Visibility.Visible;
txtSizeChangeTitle.Text = App.Text("Diff.LFS"); txtSizeChangeTitle.Text = App.Text("Diff.LFS");
@ -175,7 +189,6 @@ namespace SourceGit.Views.Widgets {
loading.Visibility = Visibility.Collapsed; loading.Visibility = Visibility.Collapsed;
mask.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed;
toolbarOptions.Visibility = Visibility.Collapsed;
noChange.Visibility = Visibility.Visible; noChange.Visibility = Visibility.Visible;
}); });
} }
@ -207,11 +220,12 @@ namespace SourceGit.Views.Widgets {
loading.Visibility = Visibility.Collapsed; loading.Visibility = Visibility.Collapsed;
mask.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed;
toolbarOptions.Visibility = Visibility.Visible; toolbarOptions.Visibility = Visibility.Visible;
textDiff.Visibility = Visibility.Visible;
var createEditor = editors.Count == 0; var createEditor = editors.Count == 0;
var lineNumberWidth = CalcLineNumberColWidth(lastOldLine, lastNewLine); var lineNumberWidth = CalcLineNumberColWidth(lastOldLine, lastNewLine);
var minWidth = textDiff.ActualWidth - lineNumberWidth * 2; var minWidth = body.ActualWidth - lineNumberWidth * 2;
if (textDiff.ActualHeight < cachedTextChanges.Count * 16) minWidth -= 8; if (body.ActualHeight - 26 < cachedTextChanges.Count * 16) minWidth -= 8;
DataGrid editor; DataGrid editor;
if (createEditor) { if (createEditor) {
@ -272,11 +286,12 @@ namespace SourceGit.Views.Widgets {
loading.Visibility = Visibility.Collapsed; loading.Visibility = Visibility.Collapsed;
mask.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed;
toolbarOptions.Visibility = Visibility.Visible; toolbarOptions.Visibility = Visibility.Visible;
textDiff.Visibility = Visibility.Visible;
var createEditor = editors.Count == 0; var createEditor = editors.Count == 0;
var lineNumberWidth = CalcLineNumberColWidth(lastOldLine, lastNewLine); var lineNumberWidth = CalcLineNumberColWidth(lastOldLine, lastNewLine);
var minWidth = textDiff.ActualWidth / 2 - lineNumberWidth; var minWidth = body.ActualWidth / 2 - lineNumberWidth;
if (textDiff.ActualHeight < newSideBlocks.Count * 16) minWidth -= 8; if (body.ActualHeight - 26 < newSideBlocks.Count * 16) minWidth -= 8;
DataGrid oldEditor, newEditor; DataGrid oldEditor, newEditor;
if (createEditor) { if (createEditor) {
@ -441,11 +456,11 @@ namespace SourceGit.Views.Widgets {
private void OnTextDiffSizeChanged(object sender, SizeChangedEventArgs e) { private void OnTextDiffSizeChanged(object sender, SizeChangedEventArgs e) {
if (editors.Count == 0) return; 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++) { for (int i = 0; i < editors.Count; i++) {
var editor = editors[i]; var editor = editors[i];
var minWidth = total - editor.NonFrozenColumnsViewportHorizontalOffset; 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; var lastColumn = editor.Columns.Count - 1;
editor.Columns[lastColumn].MinWidth = minWidth; editor.Columns[lastColumn].MinWidth = minWidth;

View file

@ -53,16 +53,24 @@ namespace SourceGit.Views.Widgets {
btnCommitAndPush.Visibility = Visibility.Collapsed; btnCommitAndPush.Visibility = Visibility.Collapsed;
} }
var diffTarget = unstagedContainer.DiffTarget;
if (diffTarget == null) diffTarget = stagedContainer.DiffTarget;
if (diffTarget == null) {
mergePanel.Visibility = Visibility.Collapsed; mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Reset();
} else if (diffTarget.IsConflit) { var diffTarget = unstagedContainer.DiffTarget;
if (diffTarget != null) {
if (diffTarget.IsConflit) {
mergePanel.Visibility = Visibility.Visible; mergePanel.Visibility = Visibility.Visible;
diffViewer.Reset(); diffViewer.Reset();
} else { } else {
mergePanel.Visibility = Visibility.Collapsed; diffViewer.Reload();
}
return;
}
diffTarget = stagedContainer.DiffTarget;
if (diffTarget == null) {
diffViewer.Reset();
} else {
diffViewer.Reload(); diffViewer.Reload();
} }
} }
@ -145,14 +153,16 @@ namespace SourceGit.Views.Widgets {
ExtraArgs = "--no-index", ExtraArgs = "--no-index",
Path = change.Path, Path = change.Path,
OrgPath = "/dev/null", OrgPath = "/dev/null",
UseLFS = isLFSEnabled UseLFS = isLFSEnabled,
WCChanges = true,
}); });
break; break;
default: default:
diffViewer.Diff(repo.Path, new DiffViewer.Option() { diffViewer.Diff(repo.Path, new DiffViewer.Option() {
Path = change.Path, Path = change.Path,
OrgPath = change.OriginalPath, OrgPath = change.OriginalPath,
UseLFS = isLFSEnabled UseLFS = isLFSEnabled,
WCChanges = true,
}); });
break; break;
} }