Skip to content

Commit 203f1a9

Browse files
committed
Merge pull request #765 from embedcard/Eben_PerfImprovePart1
Perf improve part1
2 parents c8b59c7 + 4d6f532 commit 203f1a9

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
8484
List<Branch> possibleParents;
8585
if (branchPoint == null)
8686
{
87-
possibleParents = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList();
87+
possibleParents = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true)
88+
// It fails to inherit Increment branch configuration if more than 1 parent;
89+
// therefore no point to get more than 2 parents
90+
.Take(2)
91+
.ToList();
8892
}
8993
else
9094
{

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,22 @@ public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Com
167167
}
168168
}
169169

170+
private static Dictionary<string, GitObject> _cachedPeeledTarget = new Dictionary<string, GitObject>();
171+
170172
public static GitObject PeeledTarget(this Tag tag)
171173
{
174+
GitObject cachedTarget;
175+
if(_cachedPeeledTarget.TryGetValue(tag.Target.Sha, out cachedTarget))
176+
{
177+
return cachedTarget;
178+
}
172179
var target = tag.Target;
173180

174181
while (target is TagAnnotation)
175182
{
176183
target = ((TagAnnotation)(target)).Target;
177184
}
178-
185+
_cachedPeeledTarget.Add(tag.Target.Sha, target);
179186
return target;
180187
}
181188

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ public class TaggedCommitVersionStrategy : BaseVersionStrategy
88
{
99
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
1010
{
11-
string currentBranchName = null;
12-
var head = context.Repository.Head;
13-
if (head != null)
14-
{
15-
currentBranchName = head.CanonicalName;
16-
}
17-
1811
var olderThan = context.CurrentCommit.When();
1912
var allTags = context.Repository.Tags
2013
.Where(tag => ((Commit)tag.PeeledTarget()).When() <= olderThan)
@@ -23,7 +16,7 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
2316
.Commits
2417
.SelectMany(commit =>
2518
{
26-
return allTags.Where(t => IsValidTag(context, currentBranchName, t, commit));
19+
return allTags.Where(t => IsValidTag(t, commit));
2720
})
2821
.Select(t =>
2922
{
@@ -39,19 +32,7 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
3932
.Where(a => a != null)
4033
.ToList();
4134

42-
if (tagsOnBranch.Count == 0)
43-
{
44-
yield break;
45-
}
46-
if (tagsOnBranch.Count == 1)
47-
{
48-
yield return CreateBaseVersion(context, tagsOnBranch[0]);
49-
}
50-
51-
foreach (var result in tagsOnBranch.Select(t => CreateBaseVersion(context, t)))
52-
{
53-
yield return result;
54-
}
35+
return tagsOnBranch.Select(t => CreateBaseVersion(context, t));
5536
}
5637

5738
BaseVersion CreateBaseVersion(GitVersionContext context, VersionTaggedCommit version)
@@ -66,7 +47,7 @@ protected virtual string FormatSource(VersionTaggedCommit version)
6647
return string.Format("Git tag '{0}'", version.Tag);
6748
}
6849

69-
protected virtual bool IsValidTag(GitVersionContext context, string branchName, Tag tag, Commit commit)
50+
protected virtual bool IsValidTag(Tag tag, Commit commit)
7051
{
7152
return tag.PeeledTarget() == commit;
7253
}

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TrackMergeTargetBaseVersionStrategy.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
namespace GitVersion.VersionCalculation.BaseVersionCalculators
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.Linq;
56
using LibGit2Sharp;
67

78
public class TrackMergeTargetBaseVersionStrategy : TaggedCommitVersionStrategy
89
{
9-
protected override bool IsValidTag(GitVersionContext context, string branchName, Tag tag, Commit commit)
10+
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
1011
{
11-
if (!string.IsNullOrWhiteSpace(branchName))
12+
if(!context.Configuration.TrackMergeTarget)
1213
{
13-
if (context.Configuration.TrackMergeTarget)
14-
{
15-
return IsDirectMergeFromCommit(tag, commit);
16-
}
14+
yield break;
1715
}
1816

19-
return false;
17+
string currentBranchName = null;
18+
var head = context.Repository.Head;
19+
if (head != null)
20+
{
21+
currentBranchName = head.CanonicalName;
22+
}
23+
24+
if (string.IsNullOrWhiteSpace(currentBranchName))
25+
{
26+
yield break;
27+
}
28+
29+
foreach (var version in base.GetVersions(context))
30+
{
31+
yield return version;
32+
}
33+
}
34+
35+
protected override bool IsValidTag(Tag tag, Commit commit)
36+
{
37+
return IsDirectMergeFromCommit(tag, commit);
2038
}
2139

2240
protected override string FormatSource(VersionTaggedCommit version)

0 commit comments

Comments
 (0)