mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
optimize<LFS>: do NOT test LFS filter when LFS is not enabled
This commit is contained in:
parent
2cb93d5a86
commit
9d6a411887
10 changed files with 67 additions and 33 deletions
|
@ -1,16 +0,0 @@
|
||||||
namespace SourceGit.Commands {
|
|
||||||
/// <summary>
|
|
||||||
/// 检测目录是否被LFS管理
|
|
||||||
/// </summary>
|
|
||||||
public class IsLFSFiltered : Command {
|
|
||||||
public IsLFSFiltered(string cwd, string path) {
|
|
||||||
Cwd = cwd;
|
|
||||||
Args = $"check-attr -a -z \"{path}\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Result() {
|
|
||||||
var rs = ReadToEnd();
|
|
||||||
return rs.Output.Contains("filter\0lfs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
31
src/Commands/LFS.cs
Normal file
31
src/Commands/LFS.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace SourceGit.Commands {
|
||||||
|
/// <summary>
|
||||||
|
/// LFS相关
|
||||||
|
/// </summary>
|
||||||
|
public class LFS {
|
||||||
|
private string repo;
|
||||||
|
|
||||||
|
public LFS(string repo) {
|
||||||
|
this.repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEnabled() {
|
||||||
|
var path = Path.Combine(repo, ".git", "hooks", "pre-push");
|
||||||
|
if (!File.Exists(path)) return false;
|
||||||
|
|
||||||
|
var content = File.ReadAllText(path);
|
||||||
|
return content.Contains("git lfs pre-push");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsFiltered(string path) {
|
||||||
|
var cmd = new Command();
|
||||||
|
cmd.Cwd = repo;
|
||||||
|
cmd.Args = $"check-attr -a -z \"{path}\"";
|
||||||
|
|
||||||
|
var rs = cmd.ReadToEnd();
|
||||||
|
return rs.Output.Contains("filter\0lfs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ namespace SourceGit.Commands {
|
||||||
var tmp = Path.GetTempFileName();
|
var tmp = Path.GetTempFileName();
|
||||||
var cmd = $"\"{Models.Preference.Instance.Git.Path}\" --no-pager ";
|
var cmd = $"\"{Models.Preference.Instance.Git.Path}\" --no-pager ";
|
||||||
|
|
||||||
var isLFS = new IsLFSFiltered(repo, path).Result();
|
var isLFS = new LFS(repo).IsFiltered(path);
|
||||||
if (isLFS) {
|
if (isLFS) {
|
||||||
cmd += $"show {sha}:\"{path}\" > {tmp}.lfs\n";
|
cmd += $"show {sha}:\"{path}\" > {tmp}.lfs\n";
|
||||||
cmd += $"\"{Models.Preference.Instance.Git.Path}\" --no-pager lfs smudge < {tmp}.lfs > \"{saveTo}\"\n";
|
cmd += $"\"{Models.Preference.Instance.Git.Path}\" --no-pager lfs smudge < {tmp}.lfs > \"{saveTo}\"\n";
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace SourceGit.Views {
|
||||||
txtFile.Text = $"{file}@{revision.Substring(0, 8)}";
|
txtFile.Text = $"{file}@{revision.Substring(0, 8)}";
|
||||||
|
|
||||||
Task.Run(() => {
|
Task.Run(() => {
|
||||||
var lfs = new Commands.IsLFSFiltered(repo, file).Result();
|
var lfs = new Commands.LFS(repo).IsFiltered(file);
|
||||||
if (lfs) {
|
if (lfs) {
|
||||||
Dispatcher.Invoke(() => {
|
Dispatcher.Invoke(() => {
|
||||||
loading.IsAnimating = false;
|
loading.IsAnimating = false;
|
||||||
|
|
|
@ -11,10 +11,12 @@ namespace SourceGit.Views {
|
||||||
public partial class Histories : Window {
|
public partial class Histories : Window {
|
||||||
private string repo = null;
|
private string repo = null;
|
||||||
private string file = null;
|
private string file = null;
|
||||||
|
private bool isLFSEnabled = false;
|
||||||
|
|
||||||
public Histories(string repo, string file) {
|
public Histories(string repo, string file) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
this.isLFSEnabled = new Commands.LFS(repo).IsEnabled();
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -57,7 +59,8 @@ namespace SourceGit.Views {
|
||||||
|
|
||||||
diffViewer.Diff(repo, new Widgets.DiffViewer.Option() {
|
diffViewer.Diff(repo, new Widgets.DiffViewer.Option() {
|
||||||
RevisionRange = new string[] { start, commit.SHA },
|
RevisionRange = new string[] { start, commit.SHA },
|
||||||
Path = file
|
Path = file,
|
||||||
|
UseLFS = isLFSEnabled,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
private List<Models.Change> cachedChanges = new List<Models.Change>();
|
private List<Models.Change> cachedChanges = new List<Models.Change>();
|
||||||
private string filter = null;
|
private string filter = null;
|
||||||
private bool isSelecting = false;
|
private bool isSelecting = false;
|
||||||
|
private bool isLFSEnabled = false;
|
||||||
|
|
||||||
public class ChangeNode {
|
public class ChangeNode {
|
||||||
public string Path { get; set; } = "";
|
public string Path { get; set; } = "";
|
||||||
|
@ -34,6 +35,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.range = range;
|
this.range = range;
|
||||||
this.cachedChanges = changes;
|
this.cachedChanges = changes;
|
||||||
|
this.isLFSEnabled = new Commands.LFS(repo).IsEnabled();
|
||||||
|
|
||||||
UpdateVisible();
|
UpdateVisible();
|
||||||
}
|
}
|
||||||
|
@ -214,7 +216,8 @@ namespace SourceGit.Views.Widgets {
|
||||||
diffViewer.Diff(repo, new DiffViewer.Option() {
|
diffViewer.Diff(repo, new DiffViewer.Option() {
|
||||||
RevisionRange = revisions,
|
RevisionRange = revisions,
|
||||||
Path = change.Path,
|
Path = change.Path,
|
||||||
OrgPath = change.OriginalPath
|
OrgPath = change.OriginalPath,
|
||||||
|
UseLFS = isLFSEnabled,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
public string Path = "";
|
public string Path = "";
|
||||||
public string OrgPath = null;
|
public string OrgPath = null;
|
||||||
public string ExtraArgs = "";
|
public string ExtraArgs = "";
|
||||||
|
public bool UseLFS = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Block {
|
public class Block {
|
||||||
|
@ -112,7 +113,8 @@ namespace SourceGit.Views.Widgets {
|
||||||
if (!string.IsNullOrEmpty(opt.OrgPath)) args += $"\"{opt.OrgPath}\" ";
|
if (!string.IsNullOrEmpty(opt.OrgPath)) args += $"\"{opt.OrgPath}\" ";
|
||||||
args += $"\"{opt.Path}\"";
|
args += $"\"{opt.Path}\"";
|
||||||
|
|
||||||
var isLFSObject = new Commands.IsLFSFiltered(repo, opt.Path).Result();
|
if (opt.UseLFS) {
|
||||||
|
var isLFSObject = new Commands.LFS(repo).IsFiltered(opt.Path);
|
||||||
if (isLFSObject) {
|
if (isLFSObject) {
|
||||||
var lc = new Commands.QueryLFSObjectChange(repo, args).Result();
|
var lc = new Commands.QueryLFSObjectChange(repo, args).Result();
|
||||||
if (lc.IsValid) {
|
if (lc.IsValid) {
|
||||||
|
@ -122,6 +124,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var rs = new Commands.Diff(repo, args).Result();
|
var rs = new Commands.Diff(repo, args).Result();
|
||||||
if (rs.IsBinary) {
|
if (rs.IsBinary) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
public partial class RevisionFiles : UserControl {
|
public partial class RevisionFiles : UserControl {
|
||||||
private string repo = null;
|
private string repo = null;
|
||||||
private string sha = null;
|
private string sha = null;
|
||||||
|
private bool isLFSEnabled = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件列表树节点
|
/// 文件列表树节点
|
||||||
|
@ -37,6 +38,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
public void SetData(string repo, string sha, Commands.Context cancelToken) {
|
public void SetData(string repo, string sha, Commands.Context cancelToken) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.sha = sha;
|
this.sha = sha;
|
||||||
|
this.isLFSEnabled = new Commands.LFS(repo).IsEnabled();
|
||||||
|
|
||||||
var cmd = new Commands.RevisionObjects(repo, sha) { Ctx = cancelToken };
|
var cmd = new Commands.RevisionObjects(repo, sha) { Ctx = cancelToken };
|
||||||
Task.Run(() => {
|
Task.Run(() => {
|
||||||
|
@ -220,7 +222,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
|
|
||||||
layerImagePreview.Visibility = Visibility.Visible;
|
layerImagePreview.Visibility = Visibility.Visible;
|
||||||
imgPreviewData.Source = new BitmapImage(new Uri(tmp, UriKind.Absolute));
|
imgPreviewData.Source = new BitmapImage(new Uri(tmp, UriKind.Absolute));
|
||||||
} else if (new Commands.IsLFSFiltered(repo, node.Path).Result()) {
|
} else if (isLFSEnabled && new Commands.LFS(repo).IsFiltered(node.Path)) {
|
||||||
var lfs = new Commands.QueryLFSObject(repo, sha, node.Path).Result();
|
var lfs = new Commands.QueryLFSObject(repo, sha, node.Path).Result();
|
||||||
layerRevisionPreview.Visibility = Visibility.Visible;
|
layerRevisionPreview.Visibility = Visibility.Visible;
|
||||||
iconRevisionPreview.Data = FindResource("Icon.LFS") as Geometry;
|
iconRevisionPreview.Data = FindResource("Icon.LFS") as Geometry;
|
||||||
|
|
|
@ -12,9 +12,11 @@ namespace SourceGit.Views.Widgets {
|
||||||
public partial class Stashes : UserControl {
|
public partial class Stashes : UserControl {
|
||||||
private string repo = null;
|
private string repo = null;
|
||||||
private string selected = null;
|
private string selected = null;
|
||||||
|
private bool isLFSEnabled = false;
|
||||||
|
|
||||||
public Stashes(string repo) {
|
public Stashes(string repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
this.isLFSEnabled = new Commands.LFS(repo).IsEnabled();
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +46,8 @@ namespace SourceGit.Views.Widgets {
|
||||||
diffViewer.Diff(repo, new DiffViewer.Option() {
|
diffViewer.Diff(repo, new DiffViewer.Option() {
|
||||||
RevisionRange = new string[] { selected + "^", selected },
|
RevisionRange = new string[] { selected + "^", selected },
|
||||||
Path = change.Path,
|
Path = change.Path,
|
||||||
OrgPath = change.OriginalPath
|
OrgPath = change.OriginalPath,
|
||||||
|
UseLFS = isLFSEnabled,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,13 @@ namespace SourceGit.Views.Widgets {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class WorkingCopy : UserControl {
|
public partial class WorkingCopy : UserControl {
|
||||||
private Models.Repository repo = null;
|
private Models.Repository repo = null;
|
||||||
|
private bool isLFSEnabled = false;
|
||||||
|
|
||||||
public string CommitMessage { get; set; }
|
public string CommitMessage { get; set; }
|
||||||
|
|
||||||
public WorkingCopy(Models.Repository repo) {
|
public WorkingCopy(Models.Repository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
this.isLFSEnabled = new Commands.LFS(repo.Path).IsEnabled();
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -136,13 +138,15 @@ namespace SourceGit.Views.Widgets {
|
||||||
diffViewer.Diff(repo.Path, new DiffViewer.Option() {
|
diffViewer.Diff(repo.Path, new DiffViewer.Option() {
|
||||||
ExtraArgs = "--no-index",
|
ExtraArgs = "--no-index",
|
||||||
Path = change.Path,
|
Path = change.Path,
|
||||||
OrgPath = "/dev/null"
|
OrgPath = "/dev/null",
|
||||||
|
UseLFS = isLFSEnabled
|
||||||
});
|
});
|
||||||
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
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +154,8 @@ namespace SourceGit.Views.Widgets {
|
||||||
diffViewer.Diff(repo.Path, new DiffViewer.Option() {
|
diffViewer.Diff(repo.Path, new DiffViewer.Option() {
|
||||||
ExtraArgs = "--cached",
|
ExtraArgs = "--cached",
|
||||||
Path = change.Path,
|
Path = change.Path,
|
||||||
OrgPath = change.OriginalPath
|
OrgPath = change.OriginalPath,
|
||||||
|
UseLFS = isLFSEnabled
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue