libgit2sharp
libgit2sharp copied to clipboard
Fetching history for a file VERY slow using libgit2sharp
I am attempting to use libgit2sharp to get the list of commits for a specific file in a repository. The code works, but it is VERY slow. How can I get git command line like performance from libgit2sharp?
Reproduction steps
Run the following code:
using System; using System.Collections.Generic; using System.Diagnostics; using LibGit2Sharp;
namespace GitHistoryTime
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Format is GitHistoryTime
Expected behavior
I would expect to get times similar to doing git --no-pager log --fileName. On my system, git took 0.43 seconds to return the full history
Actual behavior
On my machine, the above code took 6 minutes and 45 seconds! That is roughly 800 times slower than the git command line.
Due to the comments in https://github.com/libgit2/libgit2/issues/4428, I first tried to use a sort strategy of None, but LibGit2Sharp threw an exception that None was not valid. Why?
Version of LibGit2Sharp (release number or SHA1)
7fc4be5193dbdd08538b4b150332b5a73770e0f6
Operating system(s) tested; .NET runtime tested
Windows 10 2004 .NET 4.6.1
I have exactly the same problem:
string filePathFromBaseRepository = "prod/yomvi/android.cell/config";
DateTime afterDate = new DateTime(2021,10,10, 0,0,0);
DateTime beforeDate = DateTime.Now;
var logEntryQueryable = this.repository.Commits.QueryBy(filePathFromBaseRepository, new CommitFilter() { SortBy = CommitSortStrategies.Topological });
incrementalLogEntry = logEntryQueryable.Where(x => x.Commit.Committer.When >= afterDate && x.Commit.Committer.When < beforeDate).ToList();
The Where takes forever. Overpasses 2 minutes sometimes. It is true that it may be hundreds of commits to check but doing the same thing on shell it is some seconds at the most.
May be here: https://github.com/libgit2/libgit2sharp/issues/1705 Someone said: "I met same issue and I have to wrap a git.exe and use git log to speed up the log reading."
Same issue here. We get times around 30 seconds when looking for file history. We're considering calling git.exe and parsing its output. If anyone has already achieved that, we'd appreciate if you shared.
Is there anything new on this. I don't find the workaround of running git.exe and parsing the output very helpful.