【发布时间】:2017-08-02 19:09:29
【问题描述】:
我正在尝试使用 LibGit2Sharp 重新创建 git show-brach --independent 的功能,根据 docs 这样做:Among the <reference>s given, display only the ones that cannot be reached from any other <reference>.
到目前为止,我的最佳尝试如下:
List<Commit> GetIndependent(IRepository repo, IEnumerable<Commit> commits)
{
var indep = new List<Commit>();
foreach (var commit in commits)
{
if (repo.Commits.QueryBy(new CommitFilter
{
FirstParentOnly = false,
IncludeReachableFrom = commit,
ExcludeReachableFrom = commits.Where(x => x.Equals(commit) == false)
}).Any())
{
indep.Add(commit);
}
}
return indep;
}
不幸的是,随着历史数量的增加,这变得非常缓慢。实际上,我直接执行 git、解析输出并让 LibGit2Sharp 查找生成的 SHA 比使用上面的代码要快得多。我认为这与 Git 的一些优化有关,但 LibGit2 没有。这甚至在做我想要的吗?如果是这样,在 LibGit2Sharp 中是否有更好的方法来实现这一点?
【问题讨论】:
标签: c# git libgit2 libgit2sharp