mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
Show file size changes for binary diff
This commit is contained in:
parent
e8ef47f33d
commit
e08b7024fc
9 changed files with 163 additions and 27 deletions
|
@ -4,7 +4,6 @@ using System.IO;
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Navigation;
|
||||
|
@ -197,7 +196,11 @@ namespace SourceGit.UI {
|
|||
start = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
||||
}
|
||||
|
||||
diffViewer.Diff(repo, $"{start} {commit.SHA}", node.FilePath, node.OriginalPath);
|
||||
diffViewer.Diff(repo, new DiffViewer.Option() {
|
||||
RevisionRange = new string[] { start, commit.SHA },
|
||||
Path = node.FilePath,
|
||||
OrgPath = node.OriginalPath
|
||||
});
|
||||
}
|
||||
|
||||
private void ChangeListSelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
|
@ -211,7 +214,11 @@ namespace SourceGit.UI {
|
|||
start = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
||||
}
|
||||
|
||||
diffViewer.Diff(repo, $"{start} {commit.SHA}", change.Path, change.OriginalPath);
|
||||
diffViewer.Diff(repo, new DiffViewer.Option() {
|
||||
RevisionRange = new string[] { start, commit.SHA },
|
||||
Path = change.Path,
|
||||
OrgPath = change.OriginalPath
|
||||
});
|
||||
}
|
||||
|
||||
private void ChangeListContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
||||
|
|
|
@ -128,6 +128,29 @@
|
|||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Border x:Name="sizer" Grid.Row="1" ClipToBounds="True" Background="{StaticResource Brush.BG3}" Visibility="Collapsed">
|
||||
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
|
||||
<Label Content="BINARY DIFF" Margin="0,0,0,32" FontSize="18" FontWeight="UltraBold" Foreground="{StaticResource Brush.FG2}" HorizontalAlignment="Center"/>
|
||||
<Path Width="64" Height="64" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Binary}" Fill="{StaticResource Brush.FG2}"/>
|
||||
<Grid Margin="0,16,0,0" HorizontalAlignment="Center" TextElement.FontSize="18" TextElement.FontWeight="UltraBold">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="32"/>
|
||||
<RowDefinition Height="32"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="64"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Row="0" Grid.Column="0" Content="OLD :" Foreground="{StaticResource Brush.FG2}"/>
|
||||
<Label Grid.Row="0" Grid.Column="1" x:Name="txtOldSize" Foreground="{StaticResource Brush.FG2}" HorizontalAlignment="Right"/>
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="NEW :" Foreground="{StaticResource Brush.FG2}"/>
|
||||
<Label Grid.Row="1" Grid.Column="1" x:Name="txtNewSize" Foreground="{StaticResource Brush.FG2}" HorizontalAlignment="Right"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="mask" Grid.RowSpan="2" Background="{StaticResource Brush.BG3}" Visibility="Collapsed">
|
||||
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Opacity=".2">
|
||||
<Path Width="64" Height="64" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Diff}"/>
|
||||
|
|
|
@ -15,6 +15,16 @@ namespace SourceGit.UI {
|
|||
public partial class DiffViewer : UserControl {
|
||||
private double minWidth = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Diff options.
|
||||
/// </summary>
|
||||
public class Option {
|
||||
public string[] RevisionRange = new string[] { };
|
||||
public string Path = "";
|
||||
public string OrgPath = null;
|
||||
public string ExtraArgs = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
|
@ -28,26 +38,33 @@ namespace SourceGit.UI {
|
|||
/// </summary>
|
||||
public void Reset() {
|
||||
mask.Visibility = Visibility.Visible;
|
||||
sizer.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Diff with options.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="orgPath"></param>
|
||||
public void Diff(Git.Repository repo, string options, string path, string orgPath = null) {
|
||||
SetTitle(path, orgPath);
|
||||
/// <param name="opts"></param>
|
||||
public void Diff(Git.Repository repo, Option opts) {
|
||||
SetTitle(opts.Path, opts.OrgPath);
|
||||
|
||||
loading.Visibility = Visibility.Visible;
|
||||
sizer.Visibility = Visibility.Collapsed;
|
||||
|
||||
Task.Run(() => {
|
||||
var args = $"{options} -- ";
|
||||
if (!string.IsNullOrEmpty(orgPath)) args += $"{orgPath} ";
|
||||
args += $"\"{path}\"";
|
||||
var args = $"{opts.ExtraArgs} ";
|
||||
if (opts.RevisionRange.Length > 0) args += $"{opts.RevisionRange[0]} ";
|
||||
if (opts.RevisionRange.Length > 1) args += $"{opts.RevisionRange[1]} -- ";
|
||||
if (!string.IsNullOrEmpty(opts.OrgPath)) args += $"\"{opts.OrgPath}\" ";
|
||||
args += $"\"{opts.Path}\"";
|
||||
|
||||
var rs = Git.Diff.Run(repo, args);
|
||||
SetData(rs);
|
||||
if (rs.IsBinary) {
|
||||
SetSizeChangeData(Git.Diff.GetSizeChange(repo, opts.RevisionRange, opts.Path, opts.OrgPath));
|
||||
} else {
|
||||
SetData(rs);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -67,6 +84,20 @@ namespace SourceGit.UI {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show size changes.
|
||||
/// </summary>
|
||||
/// <param name="bc"></param>
|
||||
private void SetSizeChangeData(Git.Diff.BinaryChange bc) {
|
||||
Dispatcher.Invoke(() => {
|
||||
loading.Visibility = Visibility.Collapsed;
|
||||
mask.Visibility = Visibility.Collapsed;
|
||||
sizer.Visibility = Visibility.Visible;
|
||||
txtNewSize.Content = $"{bc.Size} Bytes";
|
||||
txtOldSize.Content = $"{bc.PreSize} Bytes";
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show diff content.
|
||||
/// </summary>
|
||||
|
@ -175,7 +206,7 @@ namespace SourceGit.UI {
|
|||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region EVENTS
|
||||
/// <summary>
|
||||
|
|
|
@ -102,7 +102,10 @@ namespace SourceGit.UI {
|
|||
var start = $"{commit.SHA}^";
|
||||
if (commit.Parents.Count == 0) start = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
||||
|
||||
diff.Diff(repo, $"{start} {commit.SHA}", file);
|
||||
diff.Diff(repo, new DiffViewer.Option() {
|
||||
RevisionRange = new string[] { start, commit.SHA },
|
||||
Path = file
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -82,7 +82,11 @@ namespace SourceGit.UI {
|
|||
var change = e.AddedItems[0] as Git.Change;
|
||||
if (change == null) return;
|
||||
|
||||
diff.Diff(repo, $"{selectedStash}^ {selectedStash}", change.Path, change.OriginalPath);
|
||||
diff.Diff(repo, new DiffViewer.Option() {
|
||||
RevisionRange = new string[] { $"{selectedStash}^", selectedStash },
|
||||
Path = change.Path,
|
||||
OrgPath = change.OriginalPath
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -133,15 +133,18 @@ namespace SourceGit.UI {
|
|||
return;
|
||||
}
|
||||
|
||||
DiffViewer.Option opt;
|
||||
switch (node.Change.WorkTree) {
|
||||
case Git.Change.Status.Added:
|
||||
case Git.Change.Status.Untracked:
|
||||
diffViewer.Diff(Repo, "--no-index", node.FilePath, "/dev/null");
|
||||
opt = new DiffViewer.Option() { ExtraArgs = "--no-index", Path = node.FilePath, OrgPath = "/dev/null" };
|
||||
break;
|
||||
default:
|
||||
diffViewer.Diff(Repo, "", node.FilePath, node.Change.OriginalPath);
|
||||
opt = new DiffViewer.Option() { Path = node.FilePath, OrgPath = node.Change.OriginalPath };
|
||||
break;
|
||||
}
|
||||
|
||||
diffViewer.Diff(Repo, opt);
|
||||
}
|
||||
|
||||
private void UnstagedListSelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
|
@ -161,15 +164,18 @@ namespace SourceGit.UI {
|
|||
return;
|
||||
}
|
||||
|
||||
DiffViewer.Option opt;
|
||||
switch (change.WorkTree) {
|
||||
case Git.Change.Status.Added:
|
||||
case Git.Change.Status.Untracked:
|
||||
diffViewer.Diff(Repo, "--no-index", change.Path, "/dev/null");
|
||||
opt = new DiffViewer.Option() { ExtraArgs = "--no-index", Path = change.Path, OrgPath = "/dev/null" };
|
||||
break;
|
||||
default:
|
||||
diffViewer.Diff(Repo, "", change.Path, change.OriginalPath);
|
||||
opt = new DiffViewer.Option() { Path = change.Path, OrgPath = change.OriginalPath };
|
||||
break;
|
||||
}
|
||||
|
||||
diffViewer.Diff(Repo, opt);
|
||||
}
|
||||
|
||||
private void SaveAsPatchFromUnstagedChanges(string path, List<Git.Change> changes) {
|
||||
|
@ -507,7 +513,11 @@ namespace SourceGit.UI {
|
|||
if (!node.IsFile) return;
|
||||
|
||||
mergePanel.Visibility = Visibility.Collapsed;
|
||||
diffViewer.Diff(Repo, "--cached", node.FilePath, node.Change.OriginalPath);
|
||||
diffViewer.Diff(Repo, new DiffViewer.Option() {
|
||||
ExtraArgs = "--cached",
|
||||
Path = node.FilePath,
|
||||
OrgPath = node.Change.OriginalPath
|
||||
});
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
@ -524,7 +534,11 @@ namespace SourceGit.UI {
|
|||
|
||||
var change = selected[0] as Git.Change;
|
||||
mergePanel.Visibility = Visibility.Collapsed;
|
||||
diffViewer.Diff(Repo, "--cached", change.Path, change.OriginalPath);
|
||||
diffViewer.Diff(Repo, new DiffViewer.Option() {
|
||||
ExtraArgs = "--cached",
|
||||
Path = change.Path,
|
||||
OrgPath = change.OriginalPath
|
||||
});
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue