libgit2 / libgit2/libgit2sharp

Fetching history for a file VERY slow using libgit2sharp

Đang mở
#1,843 4 bình luận 4 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
C#
Star
3.5k
Fork
925
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với việc tái hiện bằng C# sử dụng Repository.Commits.QueryBy(fileName, filter) và thiết lập CommitFilter.SortBy của nó, sau đó so sánh với thời gian git --no-pager log đã được báo cáo. Điều tra khoảng cách hiệu năng và lý do SortBy = None bị từ chối, sử dụng issue libgit2 liên quan 4428 làm bối cảnh. Công việc được xem là hoàn tất khi nguyên nhân và một hướng giải quyết có thể thực hiện cho hiệu năng lịch sử tệp đã được xác định.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp, git
Lĩnh vực
devtools, performance
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.