libgit2 / libgit2/libgit2sharp
RewriteHistory extremely slow
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ả
Reproduction steps
Find a repo with 3000+ commits
Run the below code against that repo to rewrite the repo history:
private static void RewriteHistory(string repoPath, ICollection<string> subFolders)
{
using (var repo = new Repository(repoPath))
{
var refs = repo.Refs.Where(r => r.CanonicalName.EndsWith("develop")).OrderBy(r => r.CanonicalName).ToList();
var commits = repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = refs }).ToArray();
var count = 0;
var stopwatch = Stopwatch.StartNew();
Logger.InfoFormat("Found {0} commits", commits.Length);
Logger.InfoFormat("Rewrite history started");
repo.Refs.RewriteHistory(new RewriteHistoryOptions
{
OnError = OnError,
OnSucceeding = OnSucceeding,
PruneEmptyCommits = true,
CommitTreeRewriter = commit =>
{
Logger.InfoFormat("Commit {0}/{1}", ++count, commits.Length);
var tree = TreeDefinition.From(commit);
foreach (var treeEntry in commit.Tree)
{
var match = subFolders.FirstOrDefault(s => treeEntry.Path.StartsWithIgnoreCase(s));
if (match == null)
tree.Remove(treeEntry.Path);
}
return tree;
}
}, commits);
Logger.InfoFormat("Rewrite history ended. Took {0}", stopwatch.Elapsed);
repo.Reset(ResetMode.Hard, repo.Head.Commits.First());
}
}
Expected behavior
This should take a reasonable time. I expect it to take a few minutes for sure but not hours. For example when running something similar in git from the command like it takes minutes. I'm sorry I don't have specific times but I can try to provide more data to compare performance if necessary.
Actual behavior
This takes 1h 43 minutes of which 1h 40 to just start the rewrite and about a couple of minutes to go through all the commits.
INFO : Found 3486 commits
INFO : Rewrite history started
[between these two log messages there is a 1h 40m gap]
INFO : Commit 1/3486
INFO : Commit 2/3486
...
INFO : Rewrite history ended. Took 01:43:51.5536779
Version of LibGit2Sharp (release number or SHA1)
0.26.0 + 2.0.267 (native)
Operating system(s) tested; .NET runtime tested
.net 4.6.1 - Win 2012R2
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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 tái hiện báo cáo với một repository chứa hơn 3.000 commit và đo độ trễ giữa “Rewrite history started” và callback CommitTreeRewriter đầu tiên. Kiểm tra lệnh gọi RewriteHistory và phần thiết lập CommitTreeRewriter được hiển thị trong issue. Được xem là hoàn tất khi cùng một lần rewrite history hoàn thành trong vài phút thay vì vài giờ, đồng thời vẫn giữ nguyên hành vi pruning đã được báo cáo.
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