Skip to content

Commit

Permalink
Merge pull request #513 from djluck/diff-perf-improvements
Browse files Browse the repository at this point in the history
Reducing CPU consumption when calculating git versions by not checkin…
  • Loading branch information
AArnott authored Sep 24, 2020
2 parents fc28ab1 + 4851c38 commit 8fd3b72
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/NerdBank.GitVersioning/GitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public static class GitExtensions
/// </summary>
private static readonly SemanticVersion SemVer0 = SemanticVersion.Parse("0.0");

private static readonly LibGit2Sharp.CompareOptions DiffOptions = new LibGit2Sharp.CompareOptions()
{
// 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.
// Calculating similarities can consume significant amounts of CPU, so disable it.
Similarity = SimilarityOptions.None,
ContextLines = 0
};

/// <summary>
/// Maximum allowable value for the <see cref="Version.Build"/>
/// and <see cref="Version.Revision"/> components.
Expand Down Expand Up @@ -843,9 +851,9 @@ bool ContainsRelevantChanges(IEnumerable<TreeEntryChanges> changes) =>
var relevantCommit =
commit.Parents.Any()
? commit.Parents.Any(parent => ContainsRelevantChanges(commit.GetRepository().Diff
.Compare<TreeChanges>(parent.Tree, commit.Tree, diffInclude)))
.Compare<TreeChanges>(parent.Tree, commit.Tree, diffInclude, DiffOptions)))
: ContainsRelevantChanges(commit.GetRepository().Diff
.Compare<TreeChanges>(null, commit.Tree, diffInclude));
.Compare<TreeChanges>(null, commit.Tree, diffInclude, DiffOptions));

if (!relevantCommit)
{
Expand Down

0 comments on commit 8fd3b72

Please sign in to comment.