forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryPickableCommits.cs
More file actions
53 lines (47 loc) · 1.88 KB
/
Copy pathQueryPickableCommits.cs
File metadata and controls
53 lines (47 loc) · 1.88 KB
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
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public class QueryPickableCommits : Command
{
public QueryPickableCommits(string repo, string based, string target)
{
WorkingDirectory = repo;
Context = repo;
Args = $"log --topo-order --cherry-pick --right-only --no-merges --no-show-signature --decorate=full --format=%H%x00%P%x00%D%x00%aN±%aE%x00%at%x00%cN±%cE%x00%ct%x00%s {based}...{target}";
}
public async Task<List<Models.Commit>> GetResultAsync()
{
var commits = new List<Models.Commit>();
try
{
using var proc = new Process();
proc.StartInfo = CreateGitStartInfo(true);
proc.Start();
while (await proc.StandardOutput.ReadLineAsync().ConfigureAwait(false) is { } line)
{
var parts = line.Split('\0');
if (parts.Length != 8)
continue;
var commit = new Models.Commit() { SHA = parts[0] };
commit.ParseParents(parts[1]);
commit.ParseDecorators(parts[2]);
commit.Author = Models.User.FindOrAdd(parts[3]);
commit.AuthorTime = ulong.Parse(parts[4]);
commit.Committer = Models.User.FindOrAdd(parts[5]);
commit.CommitterTime = ulong.Parse(parts[6]);
commit.Subject = parts[7];
commits.Add(commit);
}
await proc.WaitForExitAsync().ConfigureAwait(false);
}
catch (Exception e)
{
RaiseException($"Failed to query commits. Reason: {e.Message}");
}
return commits;
}
}
}