-
Notifications
You must be signed in to change notification settings - Fork 64
/
CommitGraphStep.cs
59 lines (47 loc) · 2.31 KB
/
CommitGraphStep.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Scalar.Common.FileSystem;
using Scalar.Common.Git;
using Scalar.Common.Tracing;
using System.IO;
using System.Text;
namespace Scalar.Common.Maintenance
{
public class CommitGraphStep : GitMaintenanceStep
{
private const string CommitGraphChainLock = "commit-graph-chain.lock";
public CommitGraphStep(ScalarContext context, bool requireObjectCacheLock = true)
: base(context, requireObjectCacheLock)
{
}
public override string Area => "CommitGraphStep";
public override string ProgressMessage => "Updating commit-graph";
protected override void PerformMaintenance()
{
using (ITracer activity = this.Context.Tracer.StartActivity("TryWriteGitCommitGraph", EventLevel.Informational))
{
string commitGraphLockPath = Path.Combine(this.Context.Enlistment.GitObjectsRoot, "info", "commit-graphs", CommitGraphChainLock);
this.Context.FileSystem.TryDeleteFile(commitGraphLockPath);
GitProcess.Result writeResult = this.RunGitCommand((process) => process.WriteCommitGraph(this.Context.Enlistment.GitObjectsRoot), nameof(GitProcess.WriteCommitGraph));
StringBuilder sb = new StringBuilder();
string commitGraphsDir = Path.Combine(this.Context.Enlistment.GitObjectsRoot, "info", "commit-graphs");
if (this.Context.FileSystem.DirectoryExists(commitGraphsDir))
{
foreach (DirectoryItemInfo info in this.Context.FileSystem.ItemsInDirectory(commitGraphsDir))
{
sb.Append(info.Name);
sb.Append(";");
}
}
activity.RelatedInfo($"commit-graph list after write: {sb}");
if (writeResult.ExitCodeIsFailure)
{
this.LogErrorAndRewriteCommitGraph(activity);
}
GitProcess.Result verifyResult = this.RunGitCommand((process) => process.VerifyCommitGraph(this.Context.Enlistment.GitObjectsRoot), nameof(GitProcess.VerifyCommitGraph));
if (!this.Stopping && verifyResult.ExitCodeIsFailure)
{
this.LogErrorAndRewriteCommitGraph(activity);
}
}
}
}
}