mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
optimize<WorkingCopy>: do not re-diff when file not changed
This commit is contained in:
parent
87d96598be
commit
aec498e9b0
4 changed files with 47 additions and 25 deletions
|
@ -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 {
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
</UserControl.Resources>
|
||||
|
||||
<Border BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1">
|
||||
<Grid>
|
||||
<Grid x:Name="body">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="26"/>
|
||||
<RowDefinition Height="*"/>
|
||||
|
@ -50,7 +50,7 @@
|
|||
Icon="{StaticResource Icon.Down}"
|
||||
ToolTip="{DynamicResource Text.Diff.Next}"
|
||||
Click="GotoNextChange"/>
|
||||
|
||||
|
||||
<controls:IconButton
|
||||
Width="14" Height="14"
|
||||
Margin="4,0"
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace SourceGit.Views.Widgets {
|
|||
public string OrgPath = null;
|
||||
public string ExtraArgs = "";
|
||||
public bool UseLFS = false;
|
||||
public bool WCChanges = false;
|
||||
}
|
||||
|
||||
private ulong seq = 0;
|
||||
|
@ -31,6 +32,7 @@ namespace SourceGit.Views.Widgets {
|
|||
private List<Models.TextChanges.Line> cachedTextChanges = null;
|
||||
private List<DataGrid> editors = new List<DataGrid>();
|
||||
private List<Rectangle> splitters = new List<Rectangle>();
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue