forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuerySubmoduleRevision.cs
More file actions
67 lines (58 loc) · 2.38 KB
/
Copy pathQuerySubmoduleRevision.cs
File metadata and controls
67 lines (58 loc) · 2.38 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public class QuerySubmoduleRevision : Command
{
public QuerySubmoduleRevision(string repo, string revision)
{
WorkingDirectory = repo;
Context = repo;
if (revision.EndsWith("-dirty", StringComparison.Ordinal))
{
_hasUncommittedChange = true;
_revision = revision.Substring(0, revision.Length - 6);
}
else
{
_hasUncommittedChange = false;
_revision = revision;
}
}
public async Task<Models.RevisionSubmodule> GetResultAsync()
{
Args = $"show --no-show-signature --decorate=full --format=%H%x00%P%x00%D%x00%aN±%aE%x00%at%x00%cN±%cE%x00%ct%x00%s%x00%B -s {_revision}";
var rs = await ReadToEndAsync().ConfigureAwait(false);
if (!rs.IsSuccess || string.IsNullOrEmpty(rs.StdOut))
return null;
var commit = new Models.Commit();
var lines = rs.StdOut.Split('\0');
if (lines.Length < 9)
return null;
commit.SHA = lines[0];
if (!string.IsNullOrEmpty(lines[1]))
commit.Parents.AddRange(lines[1].Split(' ', StringSplitOptions.RemoveEmptyEntries));
if (!string.IsNullOrEmpty(lines[2]))
commit.ParseDecorators(lines[2]);
commit.Author = Models.User.FindOrAdd(lines[3]);
commit.AuthorTime = ulong.Parse(lines[4]);
commit.Committer = Models.User.FindOrAdd(lines[5]);
commit.CommitterTime = ulong.Parse(lines[6]);
commit.Subject = lines[7];
var message = new Models.CommitFullMessage() { Message = lines[8].TrimEnd() };
var uncommittedChangesCount = 0;
if (_hasUncommittedChange)
uncommittedChangesCount = await new CountLocalChanges(WorkingDirectory, true)
.GetResultAsync()
.ConfigureAwait(false);
return new Models.RevisionSubmodule()
{
Commit = commit,
FullMessage = message,
UncommittedChanges = uncommittedChangesCount
};
}
private bool _hasUncommittedChange = false;
private string _revision = string.Empty;
}
}