55
66namespace 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-
758internal 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 ) ;
0 commit comments