2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public partial class QueryFileSize : Command
|
|
|
|
|
{
|
|
|
|
|
|
2024-03-16 02:09:27 -07:00
|
|
|
|
[GeneratedRegex(@"^\d+\s+\w+\s+[0-9a-f]+\s+(\d+)\s+.*$")]
|
|
|
|
|
private static partial Regex REG_FORMAT();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public QueryFileSize(string repo, string file, string revision)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
|
|
|
|
Args = $"ls-tree {revision} -l -- {file}";
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public long Result()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (_result != 0) return _result;
|
|
|
|
|
|
|
|
|
|
var rs = ReadToEnd();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (rs.IsSuccess)
|
|
|
|
|
{
|
2024-03-16 02:09:27 -07:00
|
|
|
|
var match = REG_FORMAT().Match(rs.StdOut);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (match.Success)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return long.Parse(match.Groups[1].Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly long _result = 0;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|