Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit b4a2262

Browse files
committed
Moved writing of objects to seperate thread
1 parent 531a061 commit b4a2262

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

GitRewrite/Delete/DeleteObjects.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Collections.Concurrent;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using GitRewrite.GitObjects;
79
using GitRewrite.IO;
810

@@ -20,17 +22,29 @@ public static void Run(string repositoryPath, IEnumerable<string> filesToDelete,
2022

2123
var rewrittenCommits = RemoveObjectsFromTree(repositoryPath, fileDeleteStrategies, folderDeleteStrategies,
2224
relevantPathes);
25+
2326
if (rewrittenCommits.Any())
2427
Refs.Update(repositoryPath, rewrittenCommits);
2528
}
2629

30+
private static readonly BlockingCollection<(byte[] Bytes, ObjectHash Hash)> ObjectsToWrite =
31+
new BlockingCollection<(byte[] Bytes, ObjectHash Hash)>();
32+
2733
public static Dictionary<ObjectHash, ObjectHash> RemoveObjectsFromTree(string vcsPath,
2834
FileDeletionStrategies filesToDelete, FolderDeletionStrategies foldersToDelete,
2935
List<byte[]> relevantPaths)
3036
{
3137
var rewrittenCommits = new Dictionary<ObjectHash, ObjectHash>();
3238
var rewrittenTrees = new ConcurrentDictionary<ObjectHash, ObjectHash>();
3339

40+
var writeThread = new Thread(collection =>
41+
{
42+
var commits = (BlockingCollection<(byte[] Bytes, ObjectHash Hash)>)collection;
43+
foreach (var commit in commits.GetConsumingEnumerable())
44+
HashContent.WriteFile(vcsPath, commit.Bytes, commit.Hash.ToString());
45+
});
46+
writeThread.Start(ObjectsToWrite);
47+
3448
foreach (var commit in CommitWalker
3549
.CommitsInOrder(vcsPath))
3650
{
@@ -46,12 +60,16 @@ public static Dictionary<ObjectHash, ObjectHash> RemoveObjectsFromTree(string vc
4660

4761
if (newCommitHash != commit.Hash)
4862
{
49-
HashContent.WriteFile(vcsPath, newCommitBytes, newCommitHash.ToString());
63+
ObjectsToWrite.Add((newCommitBytes, newCommitHash));
5064
rewrittenCommits.TryAdd(commit.Hash, newCommitHash);
5165
}
5266
}
5367
}
5468

69+
ObjectsToWrite.CompleteAdding();
70+
writeThread.Join();
71+
ObjectsToWrite.Dispose();
72+
5573
return rewrittenCommits;
5674
}
5775

@@ -153,7 +171,10 @@ private static ObjectHash RemoveObjectFromTree(
153171

154172
var fixedTree = Tree.GetFixedTree(resultingLines);
155173
if (fixedTree.Hash != tree.Hash)
156-
HashContent.WriteObject(vcsPath, fixedTree);
174+
{
175+
var bytes = GitObjectFactory.GetBytesWithHeader(GitObjectType.Tree, fixedTree.SerializeToBytes());
176+
ObjectsToWrite.Add((bytes, fixedTree.Hash));
177+
}
157178

158179
rewrittenTrees.TryAdd(treeHash, fixedTree.Hash);
159180

0 commit comments

Comments
 (0)