libgit2 / libgit2/libgit2sharp

Fetching history for a file VERY slow using libgit2sharp

Abierto
#1,843 4 comentarios 4 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
C#
Estrellas
3.5k
Forks
925
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la reproducción en C# usando Repository.Commits.QueryBy(fileName, filter) y su configuración CommitFilter.SortBy, y luego compárala con el tiempo reportado para git --no-pager log. Investiga la diferencia de rendimiento y por qué se rechaza SortBy = None, usando como contexto el issue relacionado de libgit2, el 4428. Se considera terminado cuando se hayan establecido la causa y una resolución accionable para el rendimiento del historial de archivos.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp, git
Área
devtools, performance
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.