libgit2 / libgit2/libgit2sharp
Fetching history for a file VERY slow using libgit2sharp
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
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 ");
}
else
{
string repoName = args[0];
string fileName = args[1];
Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
Repository repo = new Repository(repoName);
if (repo == null)
{
Console.WriteLine("Could not find git repository for " + repoName);
}
else
{
CommitFilter filter = new CommitFilter
{
SortBy = CommitSortStrategies.Topological
};
IEnumerable log = repo.Commits.QueryBy(fileName, filter);
if (log != null)
{
foreach (LogEntry entry in log)
{
Console.WriteLine(entry.Commit.Sha);
}
}
Console.WriteLine("Time to get the log: {0}", stopwatch.Elapsed.ToString());
}
}
}
}
}
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the C# reproduction using Repository.Commits.QueryBy(fileName, filter) and its CommitFilter.SortBy setting, then compare it with the reported git --no-pager log timing. Investigate the performance gap and why SortBy = None is rejected, using the related libgit2 issue 4428 for context. Done means the cause and an actionable resolution for file-history performance are established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- devtools, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100