mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
enhance: better LFS file detect method
This commit is contained in:
parent
f08acebb5e
commit
0da30b6b89
4 changed files with 30 additions and 34 deletions
|
@ -6,7 +6,15 @@
|
|||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
Args = $"check-attr -a -z \"{path}\"";
|
||||
Args = $"check-attr -z filter \"{path}\"";
|
||||
RaiseError = false;
|
||||
}
|
||||
|
||||
public IsLFSFiltered(string repo, string sha, string path)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
Args = $"check-attr --source {sha} -z filter \"{path}\"";
|
||||
RaiseError = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace SourceGit.Commands
|
|||
{
|
||||
public partial class QueryFileSize : Command
|
||||
{
|
||||
|
||||
[GeneratedRegex(@"^\d+\s+\w+\s+[0-9a-f]+\s+(\d+)\s+.*$")]
|
||||
private static partial Regex REG_FORMAT();
|
||||
|
||||
|
@ -25,9 +24,7 @@ namespace SourceGit.Commands
|
|||
{
|
||||
var match = REG_FORMAT().Match(rs.StdOut);
|
||||
if (match.Success)
|
||||
{
|
||||
return long.Parse(match.Groups[1].Value);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace SourceGit.Commands
|
|||
{
|
||||
public static void Run(string repo, string revision, string file, string saveTo)
|
||||
{
|
||||
var isLFSFiltered = new IsLFSFiltered(repo, file).Result();
|
||||
var isLFSFiltered = new IsLFSFiltered(repo, revision, file).Result();
|
||||
if (isLFSFiltered)
|
||||
{
|
||||
var tmpFile = saveTo + ".tmp";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia.Controls;
|
||||
|
@ -12,7 +13,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class CommitDetail : ObservableObject
|
||||
public partial class CommitDetail : ObservableObject
|
||||
{
|
||||
public DiffContext DiffContext
|
||||
{
|
||||
|
@ -164,39 +165,26 @@ namespace SourceGit.ViewModels
|
|||
|
||||
var contentStream = Commands.QueryFileContent.Run(_repo, _commit.SHA, file.Path);
|
||||
var content = new StreamReader(contentStream).ReadToEnd();
|
||||
if (content.StartsWith("version https://git-lfs.github.com/spec/", StringComparison.Ordinal))
|
||||
var matchLFS = REG_LFS_FORMAT().Match(content);
|
||||
if (matchLFS.Success)
|
||||
{
|
||||
var obj = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
|
||||
var lines = content.Split('\n', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (lines.Length == 3)
|
||||
{
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.StartsWith("oid sha256:", StringComparison.Ordinal))
|
||||
{
|
||||
obj.Object.Oid = line.Substring(11);
|
||||
}
|
||||
else if (line.StartsWith("size ", StringComparison.Ordinal))
|
||||
{
|
||||
obj.Object.Size = long.Parse(line.Substring(5));
|
||||
}
|
||||
}
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
ViewRevisionFileContent = obj;
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
obj.Object.Oid = matchLFS.Groups[1].Value;
|
||||
obj.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewRevisionFileContent = new Models.RevisionTextFile()
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
FileName = file.Path,
|
||||
Content = content
|
||||
};
|
||||
});
|
||||
ViewRevisionFileContent = new Models.RevisionTextFile()
|
||||
{
|
||||
FileName = file.Path,
|
||||
Content = content
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
case Models.ObjectType.Commit:
|
||||
|
@ -464,6 +452,9 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")]
|
||||
private static partial Regex REG_LFS_FORMAT();
|
||||
|
||||
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
|
||||
{
|
||||
".ico", ".bmp", ".jpg", ".png", ".jpeg"
|
||||
|
|
Loading…
Reference in a new issue