@@ -7,6 +7,12 @@ namespace GitVersion.Core;
7
7
8
8
internal sealed class TaggedSemanticVersionRepository : ITaggedSemanticVersionRepository
9
9
{
10
+ private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
11
+ taggedSemanticVersionsOfBranchCache = new ( ) ;
12
+ private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
13
+ taggedSemanticVersionsOfMergeTargetCache = new ( ) ;
14
+ private readonly ConcurrentDictionary < ( string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
15
+ taggedSemanticVersionsCache = new ( ) ;
10
16
private readonly ILog log ;
11
17
12
18
private GitVersionContext VersionContext => this . versionContextLazy . Value ;
@@ -24,7 +30,7 @@ public TaggedSemanticVersionRepository(ILog log, Lazy<GitVersionContext> version
24
30
this . branchRepository = branchRepository . NotNull ( ) ;
25
31
}
26
32
27
- public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersions ( IBranch branch , EffectiveConfiguration configuration )
33
+ public ILookup < ICommit , SemanticVersionWithTag > GetAllTaggedSemanticVersions ( IBranch branch , EffectiveConfiguration configuration )
28
34
{
29
35
configuration . NotNull ( ) ;
30
36
@@ -102,47 +108,9 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(IBranc
102
108
}
103
109
}
104
110
105
- return GetElements ( ) . ToLookup ( element => element . Key , element => element . Value ) ;
106
- }
107
-
108
- private readonly ConcurrentDictionary < ( string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
109
- allTaggedSemanticVersionsCache = new ( ) ;
110
-
111
- public ILookup < ICommit , SemanticVersionWithTag > GetAllTaggedSemanticVersions ( string ? tagPrefix , SemanticVersionFormat format )
112
- {
113
- tagPrefix ??= string . Empty ;
114
-
115
- IEnumerable < SemanticVersionWithTag > GetElements ( )
116
- {
117
- this . log . Info ( $ "Getting tagged semantic versions. TagPrefix: { tagPrefix } and Format: { format } ") ;
118
-
119
- foreach ( var tag in this . gitRepository . Tags )
120
- {
121
- if ( SemanticVersion . TryParse ( tag . Name . Friendly , tagPrefix , out var semanticVersion , format ) )
122
- {
123
- yield return new SemanticVersionWithTag ( semanticVersion , tag ) ;
124
- }
125
- }
126
- }
127
-
128
- bool isCached = true ;
129
- var result = allTaggedSemanticVersionsCache . GetOrAdd ( new ( tagPrefix , format ) , _ =>
130
- {
131
- isCached = false ;
132
- return GetElements ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
133
- } ) ;
134
-
135
- if ( isCached )
136
- {
137
- this . log . Debug ( $ "Returning cached tagged semantic versions. TagPrefix: { tagPrefix } and Format: { format } ") ;
138
- }
139
-
140
- return result ;
111
+ return GetElements ( ) . Distinct ( ) . ToLookup ( element => element . Key , element => element . Value ) ;
141
112
}
142
113
143
- private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
144
- taggedSemanticVersionsOfBranchCache = new ( ) ;
145
-
146
114
public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersionsOfBranch (
147
115
IBranch branch , string ? tagPrefix , SemanticVersionFormat format )
148
116
{
@@ -154,8 +122,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
154
122
using ( this . log . IndentLog ( $ "Getting tagged semantic versions on branch '{ branch . Name . Canonical } '. " +
155
123
$ "TagPrefix: { tagPrefix } and Format: { format } ") )
156
124
{
157
- var semanticVersions = GetAllTaggedSemanticVersions ( tagPrefix , format ) ;
158
-
125
+ var semanticVersions = GetTaggedSemanticVersions ( tagPrefix , format ) ;
159
126
foreach ( var commit in branch . Commits )
160
127
{
161
128
foreach ( var semanticVersion in semanticVersions [ commit ] )
@@ -170,8 +137,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
170
137
var result = taggedSemanticVersionsOfBranchCache . GetOrAdd ( new ( branch , tagPrefix , format ) , _ =>
171
138
{
172
139
isCached = false ;
173
- var semanticVersions = GetElements ( ) ;
174
- return semanticVersions . ToLookup ( element => element . Tag . Commit , element => element ) ;
140
+ return GetElements ( ) . Distinct ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
175
141
} ) ;
176
142
177
143
if ( isCached )
@@ -185,9 +151,6 @@ IEnumerable<SemanticVersionWithTag> GetElements()
185
151
return result ;
186
152
}
187
153
188
- private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
189
- taggedSemanticVersionsOfMergeTargetCache = new ( ) ;
190
-
191
154
public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersionsOfMergeTarget (
192
155
IBranch branch , string ? tagPrefix , SemanticVersionFormat format )
193
156
{
@@ -201,7 +164,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMerge
201
164
{
202
165
var shaHashSet = new HashSet < string > ( branch . Commits . Select ( element => element . Id . Sha ) ) ;
203
166
204
- foreach ( var semanticVersion in GetAllTaggedSemanticVersions ( tagPrefix , format ) . SelectMany ( _ => _ ) )
167
+ foreach ( var semanticVersion in GetTaggedSemanticVersions ( tagPrefix , format ) . SelectMany ( _ => _ ) )
205
168
{
206
169
foreach ( var commit in semanticVersion . Tag . Commit . Parents . Where ( element => shaHashSet . Contains ( element . Id . Sha ) ) )
207
170
{
@@ -215,7 +178,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMerge
215
178
var result = taggedSemanticVersionsOfMergeTargetCache . GetOrAdd ( new ( branch , tagPrefix , format ) , _ =>
216
179
{
217
180
isCached = false ;
218
- return GetElements ( ) . ToLookup ( element => element . Item1 , element => element . Item2 ) ;
181
+ return GetElements ( ) . Distinct ( ) . ToLookup ( element => element . Item1 , element => element . Item2 ) ;
219
182
} ) ;
220
183
221
184
if ( isCached )
@@ -250,7 +213,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
250
213
}
251
214
}
252
215
253
- return GetElements ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
216
+ return GetElements ( ) . Distinct ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
254
217
}
255
218
256
219
public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersionsOfReleaseBranches (
@@ -274,6 +237,38 @@ IEnumerable<SemanticVersionWithTag> GetElements()
274
237
}
275
238
}
276
239
277
- return GetElements ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
240
+ return GetElements ( ) . Distinct ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
241
+ }
242
+
243
+ private ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersions ( string ? tagPrefix , SemanticVersionFormat format )
244
+ {
245
+ tagPrefix ??= string . Empty ;
246
+
247
+ IEnumerable < SemanticVersionWithTag > GetElements ( )
248
+ {
249
+ this . log . Info ( $ "Getting tagged semantic versions. TagPrefix: { tagPrefix } and Format: { format } ") ;
250
+
251
+ foreach ( var tag in this . gitRepository . Tags )
252
+ {
253
+ if ( SemanticVersion . TryParse ( tag . Name . Friendly , tagPrefix , out var semanticVersion , format ) )
254
+ {
255
+ yield return new SemanticVersionWithTag ( semanticVersion , tag ) ;
256
+ }
257
+ }
258
+ }
259
+
260
+ bool isCached = true ;
261
+ var result = taggedSemanticVersionsCache . GetOrAdd ( new ( tagPrefix , format ) , _ =>
262
+ {
263
+ isCached = false ;
264
+ return GetElements ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
265
+ } ) ;
266
+
267
+ if ( isCached )
268
+ {
269
+ this . log . Debug ( $ "Returning cached tagged semantic versions. TagPrefix: { tagPrefix } and Format: { format } ") ;
270
+ }
271
+
272
+ return result ;
278
273
}
279
274
}
0 commit comments