diff --git a/src/Git/Diff.cs b/src/Git/Diff.cs
index 5f54e173..8fe93a1b 100644
--- a/src/Git/Diff.cs
+++ b/src/Git/Diff.cs
@@ -31,14 +31,6 @@ namespace SourceGit.Git {
Both,
}
- ///
- /// Binary change.
- ///
- public class BinaryChange {
- public long Size = 0;
- public long PreSize = 0;
- }
-
///
/// Block
///
@@ -63,9 +55,9 @@ namespace SourceGit.Git {
}
///
- /// Diff result.
+ /// Text file change.
///
- public class Result {
+ public class TextChange {
public bool IsValid = false;
public bool IsBinary = false;
public List Blocks = new List();
@@ -119,14 +111,31 @@ namespace SourceGit.Git {
}
}
+ ///
+ /// Binary change.
+ ///
+ public class BinaryChange {
+ public long Size = 0;
+ public long PreSize = 0;
+ }
+
+ ///
+ /// Change for LFS object information.
+ ///
+ public class LFSChange {
+ public LFSObject Old;
+ public LFSObject New;
+ public bool IsValid => Old != null || New != null;
+ }
+
///
/// Run diff process.
///
///
///
///
- public static Result Run(Repository repo, string args) {
- var rs = new Result();
+ public static TextChange GetTextChange(Repository repo, string args) {
+ var rs = new TextChange();
var current = new Block();
var left = 0;
var right = 0;
@@ -259,5 +268,37 @@ namespace SourceGit.Git {
return change;
}
+
+ ///
+ /// Get LFS object changes.
+ ///
+ ///
+ ///
+ ///
+ public static LFSChange GetLFSChange(Repository repo, string args) {
+ var rc = new LFSChange();
+
+ repo.RunCommand($"diff --ignore-cr-at-eol {args}", line => {
+ if (line[0] == '-') {
+ if (rc.Old == null) rc.Old = new LFSObject();
+ line = line.Substring(1);
+ if (line.StartsWith("oid sha256:")) {
+ rc.Old.OID = line.Substring(11);
+ } else if (line.StartsWith("size ")) {
+ rc.Old.Size = int.Parse(line.Substring(5));
+ }
+ } else if (line[0] == '+') {
+ if (rc.New == null) rc.New = new LFSObject();
+ line = line.Substring(1);
+ if (line.StartsWith("oid sha256:")) {
+ rc.New.OID = line.Substring(11);
+ } else if (line.StartsWith("size ")) {
+ rc.New.Size = int.Parse(line.Substring(5));
+ }
+ }
+ });
+
+ return rc;
+ }
}
}
diff --git a/src/Git/LFS.cs b/src/Git/LFS.cs
new file mode 100644
index 00000000..3b4c5a92
--- /dev/null
+++ b/src/Git/LFS.cs
@@ -0,0 +1,18 @@
+namespace SourceGit.Git {
+
+ ///
+ /// Object filtered by LFS
+ ///
+ public class LFSObject {
+
+ ///
+ /// Object id
+ ///
+ public string OID { get; set; }
+
+ ///
+ /// Object size.
+ ///
+ public long Size { get; set; }
+ }
+}
diff --git a/src/Git/Repository.cs b/src/Git/Repository.cs
index dcccc4f3..4a602d5f 100644
--- a/src/Git/Repository.cs
+++ b/src/Git/Repository.cs
@@ -999,11 +999,46 @@ namespace SourceGit.Git {
///
public long GetFileSize(string sha, string path) {
long size = 0;
+
RunCommand($"cat-file -s {sha}:\"{path}\"", line => {
if (!long.TryParse(line, out size)) size = 0;
});
+
return size;
}
+
+ ///
+ /// Detect if a file is managed by LFS.
+ ///
+ /// File path
+ ///
+ public bool IsLFSFiltered(string path) {
+ bool ok = false;
+ RunCommand($"check-attr -a -z \"{path}\"", line => {
+ ok = ok || line.Contains("filter\0lfs");
+ });
+ return ok;
+ }
+
+ ///
+ /// Get LFS object information.
+ ///
+ ///
+ ///
+ ///
+ public LFSObject GetLFSObject(string sha, string path) {
+ LFSObject obj = new LFSObject();
+
+ RunCommand($"show {sha}:\"{path}\"", line => {
+ if (line.StartsWith("oid")) {
+ obj.OID = line.Substring(3).Replace("sha256:", "").Trim();
+ } else if (line.StartsWith("size")) {
+ obj.Size = int.Parse(line.Substring(4).Trim());
+ }
+ });
+
+ return obj;
+ }
#endregion
#region METHOD_GITFLOW
diff --git a/src/Resources/Icons.xaml b/src/Resources/Icons.xaml
index 7ae6c7b1..e56667f5 100644
--- a/src/Resources/Icons.xaml
+++ b/src/Resources/Icons.xaml
@@ -2,7 +2,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
M1004.824 466.4L557.72 19.328c-25.728-25.76-67.488-25.76-93.28 0L360.568 123.2l78.176 78.176c12.544-5.984 26.56-9.376 41.376-9.376 53.024 0 96 42.976 96 96 0 14.816-3.36 28.864-9.376 41.376l127.968 127.968c12.544-5.984 26.56-9.376 41.376-9.376 53.024 0 96 42.976 96 96s-42.976 96-96 96-96-42.976-96-96c0-14.816 3.36-28.864 9.376-41.376L521.496 374.624a88.837 88.837 0 0 1-9.376 3.872v266.976c37.28 13.184 64 48.704 64 90.528 0 53.024-42.976 96-96 96s-96-42.976-96-96c0-41.792 26.72-77.344 64-90.528V378.496c-37.28-13.184-64-48.704-64-90.528 0-14.816 3.36-28.864 9.376-41.376l-78.176-78.176L19.416 464.288c-25.76 25.792-25.76 67.52 0 93.28l447.136 447.072c25.728 25.76 67.488 25.76 93.28 0l444.992-444.992c25.76-25.76 25.76-67.552 0-93.28z
M557.696 545.347L789.873 402.66c23.998-14.999 31.297-46.496 16.398-70.493-14.798-23.798-45.995-31.197-69.993-16.699L506.501 456.555 277.123 315.37c-24.098-14.798-55.595-7.3-70.493 16.799-14.799 24.097-7.3 55.594 16.798 70.493l231.778 142.586V819.12c0 28.297 22.897 51.195 51.195 51.195 28.297 0 51.195-22.898 51.195-51.195V545.347h0.1zM506.5 0l443.356 255.975v511.95L506.501 1023.9 63.144 767.925v-511.95L506.5 0z
-
+ M169.984 470.016l0 84.010667 86.016 0 0-84.010667-86.016 0zM86.016 598.016l0-171.989333 852.010667 0 0 171.989333-852.010667 0zM256 297.984l0-84.010667-86.016 0 0 84.010667 86.016 0zM86.016 169.984l852.010667 0 0 171.989333-852.010667 0 0-171.989333zM169.984 726.016l0 84.010667 86.016 0 0-84.010667-86.016 0zM86.016 854.016l0-171.989333 852.010667 0 0 171.989333-852.010667 0z
+
M753.613 996.727L269.38 511.505 754.602 27.272z
M270.387 27.273L754.62 512.495 269.398 996.728z
diff --git a/src/UI/CommitViewer.xaml.cs b/src/UI/CommitViewer.xaml.cs
index fb1cf2cd..40a3e222 100644
--- a/src/UI/CommitViewer.xaml.cs
+++ b/src/UI/CommitViewer.xaml.cs
@@ -368,16 +368,23 @@ namespace SourceGit.UI {
switch (node.CommitObject.Kind) {
case Git.Commit.Object.Type.Blob:
- await Task.Run(() => {
- var isBinary = false;
- var data = commit.GetTextFileContent(repo, node.FilePath, out isBinary);
+ if (repo.IsLFSFiltered(node.FilePath)) {
+ var obj = repo.GetLFSObject(commit.SHA, node.FilePath);
+ maskRevision.Visibility = Visibility.Visible;
+ iconPreviewRevision.Data = FindResource("Icon.LFS") as Geometry;
+ txtPreviewRevision.Content = $"LFS SIZE: {obj.Size} Bytes";
+ } else {
+ await Task.Run(() => {
+ var isBinary = false;
+ var data = commit.GetTextFileContent(repo, node.FilePath, out isBinary);
- if (isBinary) {
- Dispatcher.Invoke(() => maskPreviewNotSupported.Visibility = Visibility.Visible);
- } else {
- Dispatcher.Invoke(() => filePreview.Text = data);
- }
- });
+ if (isBinary) {
+ Dispatcher.Invoke(() => maskPreviewNotSupported.Visibility = Visibility.Visible);
+ } else {
+ Dispatcher.Invoke(() => filePreview.Text = data);
+ }
+ });
+ }
break;
case Git.Commit.Object.Type.Tag:
maskRevision.Visibility = Visibility.Visible;
diff --git a/src/UI/DiffViewer.xaml b/src/UI/DiffViewer.xaml
index 57828937..f601bda7 100644
--- a/src/UI/DiffViewer.xaml
+++ b/src/UI/DiffViewer.xaml
@@ -164,7 +164,7 @@
-
+
diff --git a/src/UI/DiffViewer.xaml.cs b/src/UI/DiffViewer.xaml.cs
index 5f22b1af..b4aa5754 100644
--- a/src/UI/DiffViewer.xaml.cs
+++ b/src/UI/DiffViewer.xaml.cs
@@ -64,11 +64,22 @@ namespace SourceGit.UI {
if (!string.IsNullOrEmpty(opts.OrgPath)) args += $"\"{opts.OrgPath}\" ";
args += $"\"{opts.Path}\"";
- var rs = Git.Diff.Run(repo, args);
+ if (repo.IsLFSFiltered(opts.Path)) {
+ var lc = Git.Diff.GetLFSChange(repo, args);
+ if (lc.IsValid) {
+ SetLFSChange(lc);
+ } else {
+ SetSame();
+ }
+
+ return;
+ }
+
+ var rs = Git.Diff.GetTextChange(repo, args);
if (rs.IsBinary) {
- SetSizeChangeData(Git.Diff.GetSizeChange(repo, opts.RevisionRange, opts.Path, opts.OrgPath));
+ SetBinaryChange(Git.Diff.GetSizeChange(repo, opts.RevisionRange, opts.Path, opts.OrgPath));
} else if (rs.Blocks.Count > 0) {
- SetData(rs);
+ SetTextChange(rs);
} else {
SetSame();
}
@@ -91,36 +102,11 @@ namespace SourceGit.UI {
}
}
- ///
- /// Show size changes.
- ///
- ///
- private void SetSizeChangeData(Git.Diff.BinaryChange bc) {
- Dispatcher.Invoke(() => {
- loading.Visibility = Visibility.Collapsed;
- sizeChange.Visibility = Visibility.Visible;
- diffNavigation.Visibility = Visibility.Collapsed;
- txtNewSize.Content = $"{bc.Size} Bytes";
- txtOldSize.Content = $"{bc.PreSize} Bytes";
- });
- }
-
- ///
- /// Show no changes or only EOL changes.
- ///
- private void SetSame() {
- Dispatcher.Invoke(() => {
- loading.Visibility = Visibility.Collapsed;
- noChange.Visibility = Visibility.Visible;
- diffNavigation.Visibility = Visibility.Collapsed;
- });
- }
-
///
/// Show diff content.
///
///
- private void SetData(Git.Diff.Result rs) {
+ private void SetTextChange(Git.Diff.TextChange rs) {
Dispatcher.Invoke(() => {
loading.Visibility = Visibility.Collapsed;
textChange.Visibility = Visibility.Visible;
@@ -141,6 +127,50 @@ namespace SourceGit.UI {
});
}
+ ///
+ /// Show size changes.
+ ///
+ ///
+ private void SetBinaryChange(Git.Diff.BinaryChange bc) {
+ Dispatcher.Invoke(() => {
+ loading.Visibility = Visibility.Collapsed;
+ sizeChange.Visibility = Visibility.Visible;
+ diffNavigation.Visibility = Visibility.Collapsed;
+ txtSizeChangeTitle.Content = "BINARY DIFF";
+ txtNewSize.Content = $"{bc.Size} Bytes";
+ txtOldSize.Content = $"{bc.PreSize} Bytes";
+ });
+ }
+
+ ///
+ /// Show size changes.
+ ///
+ ///
+ private void SetLFSChange(Git.Diff.LFSChange lc) {
+ Dispatcher.Invoke(() => {
+ var oldSize = lc.Old == null ? 0 : lc.Old.Size;
+ var newSize = lc.New == null ? 0 : lc.New.Size;
+
+ loading.Visibility = Visibility.Collapsed;
+ sizeChange.Visibility = Visibility.Visible;
+ diffNavigation.Visibility = Visibility.Collapsed;
+ txtSizeChangeTitle.Content = "LFS OBJECT CHANGE";
+ txtNewSize.Content = $"{newSize} Bytes";
+ txtOldSize.Content = $"{oldSize} Bytes";
+ });
+ }
+
+ ///
+ /// Show no changes or only EOL changes.
+ ///
+ private void SetSame() {
+ Dispatcher.Invoke(() => {
+ loading.Visibility = Visibility.Collapsed;
+ noChange.Visibility = Visibility.Visible;
+ diffNavigation.Visibility = Visibility.Collapsed;
+ });
+ }
+
///
/// Make paragraph.
///