libgit2 / libgit2/libgit2sharp

OutOfMemory Error with Repository.Diff.Compare<Patch>(...)

Đang mở
#1,411 2 bình luận 0 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 get an OutOfMemoryException from Repository.Diff with v0.22.0:

LibGit2Sharp.LibGit2SharpException: Out of memory
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in c:\Git\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 160
   at LibGit2Sharp.Core.Proxy.git_patch_from_diff(DiffSafeHandle diff, Int32 idx) in c:\Git\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 1555
   at LibGit2Sharp.PatchStats..ctor(DiffSafeHandle diff) in c:\Git\libgit2sharp\LibGit2Sharp\PatchStats.cs:line 31
   at LibGit2Sharp.Diff.<.cctor>b__1d(DiffSafeHandle diff) in c:\Git\libgit2sharp\LibGit2Sharp\Diff.cs:line 106
   at LibGit2Sharp.Diff.BuildDiffResult[T](DiffSafeHandle diff) in c:\Git\libgit2sharp\LibGit2Sharp\Diff.cs:line 120
   at LibGit2Sharp.Diff.Compare[T](Tree oldTree, Tree newTree, IEnumerable`1 paths, ExplicitPathsOptions explicitPathsOptions, CompareOptions compareOptions) in c:\Git\libgit2sharp\LibGit2Sharp\Diff.cs:line 246
   at LibGit2Sharp.Diff.Compare[T](Tree oldTree, Tree newTree) in c:\Git\libgit2sharp\LibGit2Sharp\Diff.cs:line 157
   at ABB.QueryManager.Models.Git.GitCodeChurnToCsvConverter.<GetRowData>d__7.MoveNext() in C:\Workspace\Source\TeamMetrics\QueryManager\QueryManager\Models\Git\GitCodeChurnToCsvConverter.cs:line 52

I'm trying to produce some basic code churn statistics from a Git repository. As some context, I'm implementing this in an ASP.NET application in a Hangfire job.

For each branch, I'm iterating over all of the commits and comparing them to their predecessor. I generate a patch per commit, and generate data for each file path in the commit. Here is the code I'm using:

foreach (var branch in repo.Branches.Where(b => b.Tip.Committer.When >= startDate))
{
	Commit nextCommit = null;
	foreach (var currentCommit in branch.Commits.Where(c => c.Committer.When >= startDate))
	{
		if(null == nextCommit)
		{
			foreach (var change in repo.Diff.Compare<Patch>(currentCommit.Tree, nextCommit.Tree))
			{
				var data = new string[]
				{
					nextCommit.Id.Sha,
					branch.FriendlyName,
					change.Path,
					change.Status.ToString(),
					change.IsBinaryComparison.ToString(),
					GetFileSize(nextCommit, change.Path).ToString(),
					GetLineCount(nextCommit, change.Path).ToString(),
					change.LinesAdded.ToString(),
					change.LinesDeleted.ToString()
				}
				yield return data;
			}
		}
		nextCommit = currentCommit;
	}
}

I found this related Stack Overflow question: libgit2sharp.Patch outofmemory. I tried changing my code to produce both a TreeChanges and a PatchStats, but it fails as well.

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 bằng cách lần theo đường dẫn lời gọi được báo cáo qua Core/Ensure.cs, Core/Proxy.cs, PatchStats.cs và Diff.cs, sau đó xem lại cuộc thảo luận Stack Overflow được liên kết. Tái hiện lỗi bằng Repository.Diff.Compare trên một repository có lịch sử commit tương đương và xác định thao tác nào giữ lại quá nhiều bộ nhớ. Công việc được xem là hoàn tất khi phép so sánh hoàn thành mà không xảy ra OutOfMemoryException đã báo cáo và đã bổ sung kiểm thử hồi quy cho trường hợp bị lỗi.

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
35/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.