c# - 限制在 LibGit2Sharp 中查询的提交数量?

标签 c# libgit2 libgit2sharp

我在做一个循环:

using LibGit2Sharp;

var filter = new Filter { Since = repo.Refs };
IEnumerable<Commit> commits = repo.Commits.QueryBy(filter);

foreach (Commit commit in commits)
{
     //Do stuff...
}

它工作正常,但有什么方法可以限制结果的数量吗?例如,我想获得最新的 100 个提交,而忘记旧的。

最佳答案

使用 LINQ 的 Take 怎么样?

var commits = repo.Commits.QueryBy(new LibGit2Sharp.CommitFilter{ Since = repo.Refs });
foreach (LibGit2Sharp.Commit commit in commits.Take(100))
{
    //...
}

检查 CommitCollection 的代码看起来它真的只会返回 100 次提交(所以它不会查找所有内容然后取 100 次)。

并且您可以使用 Filter.SortBy 属性设置所需的排序顺序。

关于c# - 限制在 LibGit2Sharp 中查询的提交数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10555831/

相关文章:

c# - linq to sql通过多个ID字段链接对象

c# - 验证 C# WinForms 代码在 Visual Studio 2008 中工作的正确方法是什么?

c# - 如何从 LINQ 中的列列表中选择非空值

git - 如何使用 LibGit2(Sharp) 为 Git 存储库构建版本树

windows - 是否有人使用 libgit2、libgit2sharp、Ngit 来替代 msysgit 的 Windows?

c# - 如何使用 RichText 在 EPPlus 的单个单元格中获取换行符

git - 在 git2go (libgit2) 中查找包含指定 blob 对象的提交

c# - git 日志路径的 LibGit2Sharp 等价物是什么?

libgit2 - 未能创建提交 : current tip is not the first parent error during commit in libgit2

asp.net - git 版本号 C#