-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy pathQueryTags.cs
More file actions
55 lines (46 loc) · 1.86 KB
/
QueryTags.cs
File metadata and controls
55 lines (46 loc) · 1.86 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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public class QueryTags : Command
{
public QueryTags(string repo)
{
_boundary = $"----- BOUNDARY OF TAGS {Guid.NewGuid()} -----";
Context = repo;
WorkingDirectory = repo;
Args = $"tag -l --format=\"{_boundary}%(refname)%00%(objecttype)%00%(objectname)%00%(*objectname)%00%(taggername)±%(taggeremail)%00%(creatordate:unix)%00%(contents:subject)%0a%0a%(contents:body)\"";
}
public async Task<List<Models.Tag>> GetResultAsync()
{
var tags = new List<Models.Tag>();
var rs = await ReadToEndAsync().ConfigureAwait(false);
if (!rs.IsSuccess)
return tags;
var records = rs.StdOut.Split(_boundary, StringSplitOptions.RemoveEmptyEntries);
foreach (var record in records)
{
var subs = record.Split('\0');
if (subs.Length != 7)
continue;
var name = subs[0].Substring(10);
var message = subs[6].Trim();
if (!string.IsNullOrEmpty(message) && message.Equals(name, StringComparison.Ordinal))
message = null;
ulong.TryParse(subs[5], out var creatorDate);
tags.Add(new Models.Tag()
{
Name = name,
IsAnnotated = subs[1].Equals("tag", StringComparison.Ordinal),
SHA = string.IsNullOrEmpty(subs[3]) ? subs[2] : subs[3],
Creator = Models.User.FindOrAdd(subs[4]),
CreatorDate = creatorDate,
Message = message,
});
}
return tags;
}
private readonly string _boundary;
}
}