Skip to content

Commit c8c04f3

Browse files
committed
Integrate code review suggestions
1 parent 9dcfc30 commit c8c04f3

File tree

7 files changed

+86
-94
lines changed

7 files changed

+86
-94
lines changed
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using GitVersion.Extensions;
2-
using GitVersion.VersionCalculation;
32

43
namespace GitVersion.Configuration;
54

@@ -8,12 +7,4 @@ public record EffectiveBranchConfiguration(EffectiveConfiguration Value, IBranch
87
public IBranch Branch { get; } = Branch.NotNull();
98

109
public EffectiveConfiguration Value { get; } = Value.NotNull();
11-
12-
public NextVersion CreateNextVersion(BaseVersion baseVersion, SemanticVersion incrementedVersion)
13-
{
14-
incrementedVersion.NotNull();
15-
baseVersion.NotNull();
16-
17-
return new NextVersion(incrementedVersion, baseVersion, this);
18-
}
1910
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using GitVersion.Configuration;
2+
using GitVersion.Extensions;
3+
4+
namespace GitVersion.Core;
5+
6+
internal sealed class BranchRepository : IBranchRepository
7+
{
8+
private GitVersionContext VersionContext => this.versionContextLazy.Value;
9+
private readonly Lazy<GitVersionContext> versionContextLazy;
10+
11+
private readonly IGitRepository gitRepository;
12+
13+
public BranchRepository(Lazy<GitVersionContext> versionContext, IGitRepository gitRepository)
14+
{
15+
this.versionContextLazy = versionContext.NotNull();
16+
this.gitRepository = gitRepository.NotNull();
17+
}
18+
19+
public IEnumerable<IBranch> GetMainlineBranches(params IBranch[] excludeBranches)
20+
=> GetBranches(new HashSet<IBranch>(excludeBranches), configuration => configuration.IsMainline == true);
21+
22+
public IEnumerable<IBranch> GetReleaseBranches(params IBranch[] excludeBranches)
23+
=> GetBranches(new HashSet<IBranch>(excludeBranches), configuration => configuration.IsReleaseBranch == true);
24+
25+
private IEnumerable<IBranch> GetBranches(HashSet<IBranch> excludeBranches, Func<IBranchConfiguration, bool> predicate)
26+
{
27+
predicate.NotNull();
28+
29+
foreach (var branch in this.gitRepository.Branches)
30+
{
31+
if (!excludeBranches.Contains(branch))
32+
{
33+
var branchConfiguration = VersionContext.Configuration.GetBranchConfiguration(branch.Name);
34+
if (predicate(branchConfiguration))
35+
{
36+
yield return branch;
37+
}
38+
}
39+
}
40+
}
41+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace GitVersion.Core;
2+
3+
internal interface IBranchRepository
4+
{
5+
IEnumerable<IBranch> GetMainlineBranches(params IBranch[] excludeBranches);
6+
7+
IEnumerable<IBranch> GetReleaseBranches(params IBranch[] excludeBranches);
8+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using GitVersion.Configuration;
2+
3+
namespace GitVersion.Core;
4+
5+
internal interface ITaggedSemanticVersionRepository
6+
{
7+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(IBranch branch, EffectiveConfiguration configuration);
8+
9+
ILookup<ICommit, SemanticVersionWithTag> GetAllTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format);
10+
11+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfBranch(
12+
IBranch branch,
13+
string? tagPrefix,
14+
SemanticVersionFormat format);
15+
16+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMergeTarget(
17+
IBranch branch,
18+
string? tagPrefix,
19+
SemanticVersionFormat format);
20+
21+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainlineBranches(
22+
string? tagPrefix,
23+
SemanticVersionFormat format,
24+
params IBranch[] excludeBranches);
25+
26+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfReleaseBranches(
27+
string? tagPrefix,
28+
SemanticVersionFormat format,
29+
params IBranch[] excludeBranches);
30+
}

src/GitVersion.Core/Core/TaggedSemanticVersionService.cs

Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,6 @@
55

66
namespace GitVersion.Core;
77

8-
internal interface IBranchRepository
9-
{
10-
IEnumerable<IBranch> GetMainlineBranches(params IBranch[] excludeBranches);
11-
12-
IEnumerable<IBranch> GetReleaseBranches(params IBranch[] excludeBranches);
13-
}
14-
15-
internal sealed class BranchRepository : IBranchRepository
16-
{
17-
private GitVersionContext VersionContext => this.versionContextLazy.Value;
18-
private readonly Lazy<GitVersionContext> versionContextLazy;
19-
20-
private readonly IGitRepository gitRepository;
21-
22-
public BranchRepository(Lazy<GitVersionContext> versionContext, IGitRepository gitRepository)
23-
{
24-
this.versionContextLazy = versionContext.NotNull();
25-
this.gitRepository = gitRepository.NotNull();
26-
}
27-
28-
public IEnumerable<IBranch> GetMainlineBranches(params IBranch[] excludeBranches)
29-
=> GetBranchesWhere(new HashSet<IBranch>(excludeBranches), configuration => configuration.IsMainline == true);
30-
31-
public IEnumerable<IBranch> GetReleaseBranches(params IBranch[] excludeBranches)
32-
=> GetBranchesWhere(new HashSet<IBranch>(excludeBranches), configuration => configuration.IsReleaseBranch == true);
33-
34-
private IEnumerable<IBranch> GetBranchesWhere(HashSet<IBranch> excludeBranches, Func<IBranchConfiguration, bool> predicate)
35-
{
36-
predicate.NotNull();
37-
38-
foreach (var branch in this.gitRepository.Branches)
39-
{
40-
if (!excludeBranches.Contains(branch))
41-
{
42-
var branchConfiguration = VersionContext.Configuration.GetBranchConfiguration(branch.Name);
43-
if (predicate(branchConfiguration))
44-
{
45-
yield return branch;
46-
}
47-
}
48-
}
49-
}
50-
}
51-
52-
internal interface ITaggedSemanticVersionRepository
53-
{
54-
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(IBranch branch, EffectiveConfiguration configuration);
55-
56-
ILookup<ICommit, SemanticVersionWithTag> GetAllTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format);
57-
58-
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfBranch(
59-
IBranch branch, string? tagPrefix, SemanticVersionFormat format
60-
);
61-
62-
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMergeTarget(
63-
IBranch branch, string? tagPrefix, SemanticVersionFormat format
64-
);
65-
66-
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainlineBranches(
67-
string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches
68-
);
69-
70-
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfReleaseBranches(
71-
string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches
72-
);
73-
}
74-
758
internal sealed class TaggedSemanticVersionRepository : ITaggedSemanticVersionRepository
769
{
7710
private readonly ILog log;
@@ -173,7 +106,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(IBranc
173106
}
174107

175108
private readonly ConcurrentDictionary<(string, SemanticVersionFormat), ILookup<ICommit, SemanticVersionWithTag>>
176-
getAllTaggedSemanticVersionsCache = new();
109+
allTaggedSemanticVersionsCache = new();
177110

178111
public ILookup<ICommit, SemanticVersionWithTag> GetAllTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format)
179112
{
@@ -193,7 +126,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
193126
}
194127

195128
bool isCached = true;
196-
var result = getAllTaggedSemanticVersionsCache.GetOrAdd(new(tagPrefix, format), _ =>
129+
var result = allTaggedSemanticVersionsCache.GetOrAdd(new(tagPrefix, format), _ =>
197130
{
198131
isCached = false;
199132
return GetElements().ToLookup(element => element.Tag.Commit, element => element);
@@ -208,7 +141,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
208141
}
209142

210143
private readonly ConcurrentDictionary<(IBranch, string, SemanticVersionFormat), ILookup<ICommit, SemanticVersionWithTag>>
211-
getTaggedSemanticVersionsOfBranchCache = new();
144+
taggedSemanticVersionsOfBranchCache = new();
212145

213146
public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfBranch(
214147
IBranch branch, string? tagPrefix, SemanticVersionFormat format)
@@ -234,7 +167,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
234167
}
235168

236169
bool isCached = true;
237-
var result = getTaggedSemanticVersionsOfBranchCache.GetOrAdd(new(branch, tagPrefix, format), _ =>
170+
var result = taggedSemanticVersionsOfBranchCache.GetOrAdd(new(branch, tagPrefix, format), _ =>
238171
{
239172
isCached = false;
240173
var semanticVersions = GetElements();
@@ -253,7 +186,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
253186
}
254187

255188
private readonly ConcurrentDictionary<(IBranch, string, SemanticVersionFormat), ILookup<ICommit, SemanticVersionWithTag>>
256-
getTaggedSemanticVersionsOfMergeTargetCache = new();
189+
taggedSemanticVersionsOfMergeTargetCache = new();
257190

258191
public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMergeTarget(
259192
IBranch branch, string? tagPrefix, SemanticVersionFormat format)
@@ -279,7 +212,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMerge
279212
}
280213

281214
bool isCached = true;
282-
var result = getTaggedSemanticVersionsOfMergeTargetCache.GetOrAdd(new(branch, tagPrefix, format), _ =>
215+
var result = taggedSemanticVersionsOfMergeTargetCache.GetOrAdd(new(branch, tagPrefix, format), _ =>
283216
{
284217
isCached = false;
285218
return GetElements().ToLookup(element => element.Item1, element => element.Item2);

src/GitVersion.Core/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ GitVersion.Common.IRepositoryStore.IsCommitOnBranch(GitVersion.ICommit? baseVers
115115
GitVersion.Configuration.ConfigurationExtensions
116116
GitVersion.Configuration.EffectiveBranchConfiguration
117117
GitVersion.Configuration.EffectiveBranchConfiguration.Branch.get -> GitVersion.IBranch!
118-
GitVersion.Configuration.EffectiveBranchConfiguration.CreateNextVersion(GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.SemanticVersion! incrementedVersion) -> GitVersion.VersionCalculation.NextVersion!
119118
GitVersion.Configuration.EffectiveBranchConfiguration.EffectiveBranchConfiguration(GitVersion.Configuration.EffectiveConfiguration! Value, GitVersion.IBranch! Branch) -> void
120119
GitVersion.Configuration.EffectiveBranchConfiguration.Value.get -> GitVersion.Configuration.EffectiveConfiguration!
121120
GitVersion.Configuration.EffectiveConfiguration

src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,12 @@ private bool TryGetNextVersion([NotNullWhen(true)] out NextVersion? result,
201201
var incrementedVersion = GetIncrementedVersion(effectiveConfiguration, baseVersion, label);
202202
if (incrementedVersion.IsMatchForBranchSpecificLabel(label))
203203
{
204-
result = effectiveConfiguration.CreateNextVersion(baseVersion, incrementedVersion);
204+
result = new NextVersion(incrementedVersion, baseVersion, effectiveConfiguration);
205205
}
206206

207207
return result is not null;
208208
}
209209

210-
//private SemanticVersion GetIncrementedVersion(EffectiveBranchConfiguration configuration, BaseVersion baseVersion, string? label)
211-
//{
212-
// var incrementStrategy = incrementStrategyFinder.DetermineIncrementedField(
213-
// currentCommit: Context.CurrentCommit,
214-
// baseVersion: baseVersion,
215-
// configuration: configuration.Value
216-
// );
217-
// return baseVersion.GetSemanticVersion().IncrementVersion(incrementStrategy, label);
218-
//}
219-
220210
private SemanticVersion GetIncrementedVersion(EffectiveBranchConfiguration configuration, BaseVersion baseVersion, string? label)
221211
{
222212
if (baseVersion is BaseVersionV2 baseVersionV2)

0 commit comments

Comments
 (0)