-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathStatistics.cs
48 lines (41 loc) · 1.41 KB
/
Statistics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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} --format=%ct$%aN±%aE";
}
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.AsSpan().Slice(0, dateEndIdx);
if (double.TryParse(dateStr, out var date))
statistics.AddCommit(line.Substring(dateEndIdx + 1), date);
}
}
}