mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-27 21:27:19 -08:00
8b3d129890
* SourceGit.Commands.* should not reference code in SourceGit.ViewModels. Signed-off-by: leo <longshuang@msn.cn>
48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using System;
|
|
|
|
namespace SourceGit.Commands
|
|
{
|
|
public class Statistics : Command
|
|
{
|
|
public Statistics(string repo, int max)
|
|
{
|
|
WorkingDirectory = repo;
|
|
Context = repo;
|
|
Args = $"log --date-order --branches --remotes -{max} --pretty=format:\"%ct$%aN\"";
|
|
}
|
|
|
|
public Models.Statistics Result()
|
|
{
|
|
var statistics = new Models.Statistics();
|
|
var rs = ReadToEnd();
|
|
if (!rs.IsSuccess)
|
|
return statistics;
|
|
|
|
var start = 0;
|
|
var end = rs.StdOut.IndexOf('\n', start);
|
|
while (end > 0)
|
|
{
|
|
ParseLine(statistics, rs.StdOut.Substring(start, end - start));
|
|
start = end + 1;
|
|
end = rs.StdOut.IndexOf('\n', start);
|
|
}
|
|
|
|
if (start < rs.StdOut.Length)
|
|
ParseLine(statistics, rs.StdOut.Substring(start));
|
|
|
|
statistics.Complete();
|
|
return statistics;
|
|
}
|
|
|
|
private void ParseLine(Models.Statistics statistics, string line)
|
|
{
|
|
var dateEndIdx = line.IndexOf('$', StringComparison.Ordinal);
|
|
if (dateEndIdx == -1)
|
|
return;
|
|
|
|
var dateStr = line.Substring(0, dateEndIdx);
|
|
if (double.TryParse(dateStr, out var date))
|
|
statistics.AddCommit(line.Substring(dateEndIdx + 1), date);
|
|
}
|
|
}
|
|
}
|