libgit2 / libgit2/libgit2sharp
Fetching history for a file VERY slow using libgit2sharp
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C#
- Sterne
- 3.5k
- Forks
- 925
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der C#-Reproduktion unter Verwendung von Repository.Commits.QueryBy(fileName, filter) und der Einstellung CommitFilter.SortBy, und vergleiche sie anschließend mit der gemeldeten Zeit für git --no-pager log. Untersuche die Performance-Lücke und warum SortBy = None abgelehnt wird, und ziehe dabei das zugehörige libgit2-Issue 4428 als Kontext heran. Als erledigt gilt die Aufgabe, wenn die Ursache und eine umsetzbare Lösung für die Performance des Dateiverlaufs festgestellt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp, git
- Bereich
- devtools, performance
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100