唔。没有什么开箱即用的东西可以满足这种需求。
但是,通过向后追溯修订历史并识别添加和修改,可以收集正在检查的提交中存在的每个文件的最新更改日期。
这个怎么样?
public void LetUsTryThis()
{
using (var repo = new Repository(StandardTestRepoPath))
{
var referenceCommit = repo.Head.Tip;
IEnumerable<KeyValuePair<string, DateTimeOffset>> res = LatestChanges(repo, referenceCommit);
foreach (KeyValuePair<string, DateTimeOffset> kvp in res)
{
Console.WriteLine(string.Format("{0} - {1}", kvp.Key, kvp.Value));
}
}
}
private IEnumerable<KeyValuePair<string, DateTimeOffset>> LatestChanges(Repository repo, Commit referenceCommit)
{
IDictionary<string, DateTimeOffset> dic = new Dictionary<string, DateTimeOffset>();
var commitLog = repo.Commits.QueryBy(new CommitFilter { Since = referenceCommit })
.Concat(new[] { default(Commit) })
.Skip(1);
var mostRecent = referenceCommit;
foreach (Commit current in commitLog)
{
IEnumerable<KeyValuePair<string, DateTimeOffset>> res = ExtractAdditionsAndModifications(repo, mostRecent, current);
AddLatest(dic, res);
mostRecent = current;
}
return dic.OrderByDescending(kvp => kvp.Value);
}
private IEnumerable<KeyValuePair<string, DateTimeOffset>> ExtractAdditionsAndModifications(Repository repo, Commit next, Commit current)
{
IDictionary<string, DateTimeOffset> dic = new Dictionary<string, DateTimeOffset>();
var tc = repo.Diff.Compare(current == null ? null : current.Tree, next.Tree);
foreach (TreeEntryChanges treeEntryChanges in tc.Added)
{
dic.Add(treeEntryChanges.Path, next.Committer.When);
}
foreach (TreeEntryChanges treeEntryChanges in tc.Modified)
{
dic.Add(treeEntryChanges.Path, next.Committer.When);
}
return dic;
}
private void AddLatest(IDictionary<string, DateTimeOffset> main, IEnumerable<KeyValuePair<string, DateTimeOffset>> latest)
{
foreach (var kvp in latest)
{
if (main.ContainsKey(kvp.Key))
{
continue;
}
main.Add(kvp);
}
}