Limiting the number of requests received in LibGit2Sharp?

I am doing a loop:

using LibGit2Sharp;

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

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

It works great, but is there any way to limit the number of results? For example, I would like to get the newest 100 commits and forget about the old ones.

+3
source share
1 answer

How about using LINQ Take

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

Checking the CommitCollection code it seems that it will really only return 100 commits (so it does not look for everything, and then takes 100).

And you can set the desired sort order using the property Filter.SortBy.

+3
source

All Articles