6
6
7
7
namespace GitVersion . Core ;
8
8
9
- internal sealed class TaggedSemanticVersionRepository (
10
- ILog log ,
11
- IGitRepository gitRepository ,
12
- IBranchRepository branchRepository )
13
- : ITaggedSemanticVersionRepository
9
+ internal sealed class TaggedSemanticVersionRepository ( ILog log , IGitRepository gitRepository ) : ITaggedSemanticVersionRepository
14
10
{
15
- private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
11
+ private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , IReadOnlyList < SemanticVersionWithTag > >
16
12
taggedSemanticVersionsOfBranchCache = new ( ) ;
17
- private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
13
+ private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , IReadOnlyList < ( ICommit Key , SemanticVersionWithTag Value ) > >
18
14
taggedSemanticVersionsOfMergeTargetCache = new ( ) ;
19
- private readonly ConcurrentDictionary < ( string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
15
+ private readonly ConcurrentDictionary < ( string , SemanticVersionFormat ) , IReadOnlyList < SemanticVersionWithTag > >
20
16
taggedSemanticVersionsCache = new ( ) ;
21
17
private readonly ILog log = log . NotNull ( ) ;
22
18
23
19
private readonly IGitRepository gitRepository = gitRepository . NotNull ( ) ;
24
- private readonly IBranchRepository branchRepository = branchRepository . NotNull ( ) ;
25
-
26
- public ILookup < ICommit , SemanticVersionWithTag > GetAllTaggedSemanticVersions (
27
- IGitVersionConfiguration configuration , EffectiveConfiguration effectiveConfiguration ,
28
- IBranch branch , string ? label , DateTimeOffset ? notOlderThan )
29
- {
30
- configuration . NotNull ( ) ;
31
- effectiveConfiguration . NotNull ( ) ;
32
- branch . NotNull ( ) ;
33
-
34
- IEnumerable < ( ICommit Key , SemanticVersionWithTag Value ) > GetElements ( )
35
- {
36
- var semanticVersionsOfBranch = GetTaggedSemanticVersionsOfBranch (
37
- branch : branch ,
38
- tagPrefix : effectiveConfiguration . TagPrefix ,
39
- format : effectiveConfiguration . SemanticVersionFormat ,
40
- ignore : configuration . Ignore
41
- ) ;
42
- foreach ( var grouping in semanticVersionsOfBranch )
43
- {
44
- if ( grouping . Key . When > notOlderThan ) continue ;
45
-
46
- foreach ( var semanticVersion in grouping )
47
- {
48
- if ( semanticVersion . Value . IsMatchForBranchSpecificLabel ( label ) )
49
- {
50
- yield return new ( grouping . Key , semanticVersion ) ;
51
- }
52
- }
53
- }
54
-
55
- if ( effectiveConfiguration . TrackMergeTarget )
56
- {
57
- var semanticVersionsOfMergeTarget = GetTaggedSemanticVersionsOfMergeTarget (
58
- branch : branch ,
59
- tagPrefix : effectiveConfiguration . TagPrefix ,
60
- format : effectiveConfiguration . SemanticVersionFormat ,
61
- ignore : configuration . Ignore
62
- ) ;
63
- foreach ( var grouping in semanticVersionsOfMergeTarget )
64
- {
65
- if ( grouping . Key . When > notOlderThan ) continue ;
66
-
67
- foreach ( var semanticVersion in grouping )
68
- {
69
- if ( semanticVersion . Value . IsMatchForBranchSpecificLabel ( label ) )
70
- {
71
- yield return new ( grouping . Key , semanticVersion ) ;
72
- }
73
- }
74
- }
75
- }
76
-
77
- if ( effectiveConfiguration . TracksReleaseBranches )
78
- {
79
- var semanticVersionsOfReleaseBranches = GetTaggedSemanticVersionsOfReleaseBranches (
80
- configuration : configuration ,
81
- tagPrefix : effectiveConfiguration . TagPrefix ,
82
- format : effectiveConfiguration . SemanticVersionFormat ,
83
- excludeBranches : branch
84
- ) ;
85
- foreach ( var grouping in semanticVersionsOfReleaseBranches )
86
- {
87
- if ( grouping . Key . When > notOlderThan ) continue ;
88
-
89
- foreach ( var semanticVersion in grouping )
90
- {
91
- if ( semanticVersion . Value . IsMatchForBranchSpecificLabel ( label ) )
92
- {
93
- yield return new ( grouping . Key , semanticVersion ) ;
94
- }
95
- }
96
- }
97
- }
98
-
99
- if ( ! effectiveConfiguration . IsMainBranch && ! effectiveConfiguration . IsReleaseBranch )
100
- {
101
- var semanticVersionsOfMainlineBranches = GetTaggedSemanticVersionsOfMainBranches (
102
- configuration : configuration ,
103
- tagPrefix : effectiveConfiguration . TagPrefix ,
104
- format : effectiveConfiguration . SemanticVersionFormat ,
105
- excludeBranches : branch
106
- ) ;
107
- foreach ( var grouping in semanticVersionsOfMainlineBranches )
108
- {
109
- if ( grouping . Key . When > notOlderThan ) continue ;
110
-
111
- foreach ( var semanticVersion in grouping )
112
- {
113
- if ( semanticVersion . Value . IsMatchForBranchSpecificLabel ( label ) )
114
- {
115
- yield return new ( grouping . Key , semanticVersion ) ;
116
- }
117
- }
118
- }
119
- }
120
- }
121
-
122
- return GetElements ( ) . Distinct ( ) . OrderByDescending ( element => element . Key . When )
123
- . ToLookup ( element => element . Key , element => element . Value ) ;
124
- }
125
20
126
21
public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersionsOfBranch (
127
22
IBranch branch , string ? tagPrefix , SemanticVersionFormat format , IIgnoreConfiguration ignore )
@@ -150,8 +45,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
150
45
var result = taggedSemanticVersionsOfBranchCache . GetOrAdd ( new ( branch , tagPrefix , format ) , _ =>
151
46
{
152
47
isCached = false ;
153
- return GetElements ( ) . Distinct ( ) . OrderByDescending ( element => element . Tag . Commit . When )
154
- . ToLookup ( element => element . Tag . Commit , element => element ) ;
48
+ return GetElements ( ) . Distinct ( ) . OrderByDescending ( element => element . Tag . Commit . When ) . ToList ( ) ;
155
49
} ) ;
156
50
157
51
if ( isCached )
@@ -162,7 +56,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
162
56
) ;
163
57
}
164
58
165
- return result ;
59
+ return result . ToLookup ( element => element . Tag . Commit , element => element ) ;
166
60
}
167
61
168
62
public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersionsOfMergeTarget (
@@ -192,8 +86,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMerge
192
86
var result = taggedSemanticVersionsOfMergeTargetCache . GetOrAdd ( new ( branch , tagPrefix , format ) , _ =>
193
87
{
194
88
isCached = false ;
195
- return GetElements ( ) . Distinct ( ) . OrderByDescending ( element => element . Key . When )
196
- . ToLookup ( element => element . Key , element => element . Value ) ;
89
+ return GetElements ( ) . Distinct ( ) . OrderByDescending ( element => element . Key . When ) . ToList ( ) ;
197
90
} ) ;
198
91
199
92
if ( isCached )
@@ -204,59 +97,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMerge
204
97
) ;
205
98
}
206
99
207
- return result ;
208
- }
209
-
210
- public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersionsOfMainBranches (
211
- IGitVersionConfiguration configuration , string ? tagPrefix , SemanticVersionFormat format , params IBranch [ ] excludeBranches )
212
- {
213
- configuration . NotNull ( ) ;
214
- tagPrefix ??= string . Empty ;
215
- excludeBranches . NotNull ( ) ;
216
-
217
- IEnumerable < SemanticVersionWithTag > GetElements ( )
218
- {
219
- using ( this . log . IndentLog ( $ "Getting tagged semantic versions of mainline branches. " +
220
- $ "TagPrefix: { tagPrefix } and Format: { format } ") )
221
- {
222
- foreach ( var mainlinemBranch in branchRepository . GetMainBranches ( configuration , excludeBranches ) )
223
- {
224
- foreach ( var semanticVersion in GetTaggedSemanticVersionsOfBranch ( mainlinemBranch , tagPrefix , format , configuration . Ignore ) . SelectMany ( _ => _ ) )
225
- {
226
- yield return semanticVersion ;
227
- }
228
- }
229
- }
230
- }
231
-
232
- return GetElements ( ) . Distinct ( ) . OrderByDescending ( element => element . Tag . Commit . When )
233
- . ToLookup ( element => element . Tag . Commit , element => element ) ;
234
- }
235
-
236
- public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersionsOfReleaseBranches (
237
- IGitVersionConfiguration configuration , string ? tagPrefix , SemanticVersionFormat format , params IBranch [ ] excludeBranches )
238
- {
239
- configuration . NotNull ( ) ;
240
- tagPrefix ??= string . Empty ;
241
- excludeBranches . NotNull ( ) ;
242
-
243
- IEnumerable < SemanticVersionWithTag > GetElements ( )
244
- {
245
- using ( this . log . IndentLog ( $ "Getting tagged semantic versions of release branches. " +
246
- $ "TagPrefix: { tagPrefix } and Format: { format } ") )
247
- {
248
- foreach ( var releaseBranch in branchRepository . GetReleaseBranches ( configuration , excludeBranches ) )
249
- {
250
- foreach ( var semanticVersion in GetTaggedSemanticVersionsOfBranch ( releaseBranch , tagPrefix , format , configuration . Ignore ) . SelectMany ( _ => _ ) )
251
- {
252
- yield return semanticVersion ;
253
- }
254
- }
255
- }
256
- }
257
-
258
- return GetElements ( ) . Distinct ( ) . OrderByDescending ( element => element . Tag . Commit . When )
259
- . ToLookup ( element => element . Tag . Commit , element => element ) ;
100
+ return result . ToLookup ( element => element . Key , element => element . Value ) ;
260
101
}
261
102
262
103
public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersions (
@@ -281,15 +122,14 @@ IEnumerable<SemanticVersionWithTag> GetElements()
281
122
var result = taggedSemanticVersionsCache . GetOrAdd ( new ( tagPrefix , format ) , _ =>
282
123
{
283
124
isCached = false ;
284
- return GetElements ( ) . OrderByDescending ( element => element . Tag . Commit . When )
285
- . ToLookup ( element => element . Tag . Commit , element => element ) ;
125
+ return GetElements ( ) . OrderByDescending ( element => element . Tag . Commit . When ) . ToList ( ) ;
286
126
} ) ;
287
127
288
128
if ( isCached )
289
129
{
290
130
this . log . Debug ( $ "Returning cached tagged semantic versions. TagPrefix: { tagPrefix } and Format: { format } ") ;
291
131
}
292
132
293
- return result ;
133
+ return result . ToLookup ( element => element . Tag . Commit , element => element ) ;
294
134
}
295
135
}
0 commit comments