找到所有的祖先路径合并
问题描述:
答
首先是一些基本知识:
git的日志topic..master
var filter = new CommitFilter {
SortBy = CommitSortStrategies.Time,
Since = master,
Until = topic,
};
var commitList = repo.Commits.QueryBy (filter);
git的日志topic..master --merges
var filter = new CommitFilter {
SortBy = CommitSortStrategies.Time,
Since = master,
Until = topic,
};
var commitList = repo.Commits.QueryBy (filter);
var mergeList = commitList.Where (p => p.Parents.Count() >= 2);
现在你的问题:
git的日志topic..master --ancestry路径--merges
祖先路径=
When given a range of commits to display (e.g. commit1..commit2 or commit2 ^commit1), only display commits that exist directly on the ancestry chain between the commit1 and commit2, i.e. commits that are both descendants of commit1, and ancestors of commit2.
的-merges
容易一旦我们拥有祖先路径,就可以过滤具有多个父代的提交。获取祖先路径需要一些编码;-)
,因为这是从commitList
通过.Parents
属性返回在上面第一个例子包含DAG(向无环图)的ICommitLog
,我们需要走的图形,并得到“所有通过深度优先搜索的简单路径”找到所有非周期性路径一旦你拥有的所有simple
路径列表只是过滤它通过承诺有>=2
父母
注意:我已经在这样做了很少有C#项目,甚至简单的项目,比如计算与特定提交相关的拉取请求,都会使用这个深度优先的祖先。我倾向于远离Linq来执行此操作,因为我有huge
提交列表(仅在我搜索的子DAG内的开始到结束节点之间的100k +节点),并且由于堆栈大小而避免递归方法,但您的用例可能会/会有所不同。如果您在这一点上遇到困难,请在算法/代码问题中发布另一个问题。