mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-24 19:02:39 +08:00
- Remove all synchronous method in commands - `Command.ReadToEndAsync` now is protected method - Rename `ResultAsync` to `GetResultAsync` - Call `ConfigureAwait(false)` when there's no context Signed-off-by: leo <longshuang@msn.cn>
41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SourceGit.Commands
|
|
{
|
|
public class QueryRefsContainsCommit : Command
|
|
{
|
|
public QueryRefsContainsCommit(string repo, string commit)
|
|
{
|
|
WorkingDirectory = repo;
|
|
RaiseError = false;
|
|
Args = $"for-each-ref --format=\"%(refname)\" --contains {commit}";
|
|
}
|
|
|
|
public async Task<List<Models.Decorator>> GetResultAsync()
|
|
{
|
|
var outs = new List<Models.Decorator>();
|
|
var rs = await ReadToEndAsync().ConfigureAwait(false);
|
|
if (!rs.IsSuccess)
|
|
return outs;
|
|
|
|
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (var line in lines)
|
|
{
|
|
if (line.EndsWith("/HEAD", StringComparison.Ordinal))
|
|
continue;
|
|
|
|
if (line.StartsWith("refs/heads/", StringComparison.Ordinal))
|
|
outs.Add(new() { Name = line.Substring("refs/heads/".Length), Type = Models.DecoratorType.LocalBranchHead });
|
|
else if (line.StartsWith("refs/remotes/", StringComparison.Ordinal))
|
|
outs.Add(new() { Name = line.Substring("refs/remotes/".Length), Type = Models.DecoratorType.RemoteBranchHead });
|
|
else if (line.StartsWith("refs/tags/", StringComparison.Ordinal))
|
|
outs.Add(new() { Name = line.Substring("refs/tags/".Length), Type = Models.DecoratorType.Tag });
|
|
}
|
|
|
|
return outs;
|
|
}
|
|
}
|
|
}
|