Fetching history for a file VERY slow using libgit2sharp

Aberta
#1,843 4 comentários 4 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
38/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
csharp, git
Domínio
devtools, performance

Direção de pesquisa

Comece com a reprodução em C# usando Repository.Commits.QueryBy(fileName, filter) e sua configuração CommitFilter.SortBy, e depois compare-a com o tempo relatado para git --no-pager log. Investigue a diferença de desempenho e por que SortBy = None é rejeitado, usando a issue relacionada 4428 do libgit2 como contexto. Considera-se concluído quando a causa e uma resolução acionável para o desempenho do histórico de arquivos estiverem estabelecidas.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
C#
Estrelas
3.5k
Forks
925
Métricas de merge de PRs
Nenhum PR com merge em 30d

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de libgit2/libgit2sharp

Todas as issues de libgit2/libgit2sharp

Issues semelhantes

Mais issues de C#

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.