libgit2 / libgit2/libgit2sharp

Fetching history for a file VERY slow using libgit2sharp

オープン
#1,843 コメント 4 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
C#
スター
3.5k
フォーク
925
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Repository.Commits.QueryBy(fileName, filter) とその CommitFilter.SortBy 設定を使用した C# の再現から始め、報告されている git --no-pager log の所要時間と比較します。パフォーマンスの差と SortBy = None が拒否される理由を、関連する libgit2 issue 4428 を背景として調査します。ファイル履歴のパフォーマンスについて、原因と実行可能な解決策が確立されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, git
領域
devtools, performance
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。