forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryCommitChangedLines.cs
44 lines (39 loc) · 1.22 KB
/
QueryCommitChangedLines.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
using System.Text.RegularExpressions;
namespace SourceGit.Commands
{
public class QueryCommitChangedLines : Command
{
public QueryCommitChangedLines(string repo, string sha)
{
WorkingDirectory = repo;
Context = repo;
Args = $"show --shortstat --oneline {sha}";
_pattern = new Regex(@"(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?");
}
public (int, int) Result()
{
_addedLines = 0;
_removedLines = 0;
Exec();
return (_addedLines, _removedLines);
}
protected override void OnReadline(string line)
{
var match = _pattern.Match(line);
if (match.Success)
{
if (match.Groups[2].Success)
{
_addedLines = int.Parse(match.Groups[2].Value);
}
if (match.Groups[3].Success)
{
_removedLines = int.Parse(match.Groups[3].Value);
}
}
}
private readonly Regex _pattern;
private int _addedLines;
private int _removedLines;
}
}