feature(LFS): LFS diff and preview support

This commit is contained in:
leo 2020-09-25 16:30:28 +08:00
parent f3ee044818
commit 77ba0e6cdb
7 changed files with 184 additions and 52 deletions

View file

@ -999,11 +999,46 @@ namespace SourceGit.Git {
/// <returns></returns>
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;
}
/// <summary>
/// Detect if a file is managed by LFS.
/// </summary>
/// <param name="path">File path</param>
/// <returns></returns>
public bool IsLFSFiltered(string path) {
bool ok = false;
RunCommand($"check-attr -a -z \"{path}\"", line => {
ok = ok || line.Contains("filter\0lfs");
});
return ok;
}
/// <summary>
/// Get LFS object information.
/// </summary>
/// <param name="sha"></param>
/// <param name="path"></param>
/// <returns></returns>
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