Skip to content

Commit 8fd3b72

Browse files
authored
Merge pull request #513 from djluck/diff-perf-improvements
Reducing CPU consumption when calculating git versions by not checkin…
2 parents fc28ab1 + 4851c38 commit 8fd3b72

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/NerdBank.GitVersioning/GitExtensions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public static class GitExtensions
2626
/// </summary>
2727
private static readonly SemanticVersion SemVer0 = SemanticVersion.Parse("0.0");
2828

29+
private static readonly LibGit2Sharp.CompareOptions DiffOptions = new LibGit2Sharp.CompareOptions()
30+
{
31+
// When calculating the height of a commit, we do not care if a file has been renamed only if it has been added or removed.
32+
// Calculating similarities can consume significant amounts of CPU, so disable it.
33+
Similarity = SimilarityOptions.None,
34+
ContextLines = 0
35+
};
36+
2937
/// <summary>
3038
/// Maximum allowable value for the <see cref="Version.Build"/>
3139
/// and <see cref="Version.Revision"/> components.
@@ -843,9 +851,9 @@ bool ContainsRelevantChanges(IEnumerable<TreeEntryChanges> changes) =>
843851
var relevantCommit =
844852
commit.Parents.Any()
845853
? commit.Parents.Any(parent => ContainsRelevantChanges(commit.GetRepository().Diff
846-
.Compare<TreeChanges>(parent.Tree, commit.Tree, diffInclude)))
854+
.Compare<TreeChanges>(parent.Tree, commit.Tree, diffInclude, DiffOptions)))
847855
: ContainsRelevantChanges(commit.GetRepository().Diff
848-
.Compare<TreeChanges>(null, commit.Tree, diffInclude));
856+
.Compare<TreeChanges>(null, commit.Tree, diffInclude, DiffOptions));
849857

850858
if (!relevantCommit)
851859
{

0 commit comments

Comments
 (0)