libgit2 / libgit2/libgit2sharp

Fetching history for a file VERY slow using libgit2sharp

Ouverte
#1,843 4 commentaires 4 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
C#
Étoiles
3.5k
Forks
925
Métriques de merge des PR
Aucune PR mergée en 30 j

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la reproduction en C# utilisant Repository.Commits.QueryBy(fileName, filter) et son paramètre CommitFilter.SortBy, puis comparez-la avec le temps rapporté pour git --no-pager log. Étudiez l’écart de performances et la raison pour laquelle SortBy = None est rejeté, en utilisant l’issue libgit2 associée 4428 comme contexte. La tâche est terminée lorsque la cause et une résolution concrète pour les performances de l’historique des fichiers sont établies.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
csharp, git
Domaine
devtools, performance
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.