@@ -24,7 +24,7 @@ public TaggedSemanticVersionRepository(ILog log, Lazy<GitVersionContext> version
24
24
this . branchRepository = branchRepository . NotNull ( ) ;
25
25
}
26
26
27
- public ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersions ( IBranch branch , EffectiveConfiguration configuration )
27
+ public ILookup < ICommit , SemanticVersionWithTag > GetAllTaggedSemanticVersions ( IBranch branch , EffectiveConfiguration configuration )
28
28
{
29
29
configuration . NotNull ( ) ;
30
30
@@ -102,42 +102,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(IBranc
102
102
}
103
103
}
104
104
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 ;
105
+ return GetElements ( ) . Distinct ( ) . ToLookup ( element => element . Key , element => element . Value ) ;
141
106
}
142
107
143
108
private readonly ConcurrentDictionary < ( IBranch , string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
@@ -154,8 +119,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
154
119
using ( this . log . IndentLog ( $ "Getting tagged semantic versions on branch '{ branch . Name . Canonical } '. " +
155
120
$ "TagPrefix: { tagPrefix } and Format: { format } ") )
156
121
{
157
- var semanticVersions = GetAllTaggedSemanticVersions ( tagPrefix , format ) ;
158
-
122
+ var semanticVersions = GetTaggedSemanticVersions ( tagPrefix , format ) ;
159
123
foreach ( var commit in branch . Commits )
160
124
{
161
125
foreach ( var semanticVersion in semanticVersions [ commit ] )
@@ -170,8 +134,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
170
134
var result = taggedSemanticVersionsOfBranchCache . GetOrAdd ( new ( branch , tagPrefix , format ) , _ =>
171
135
{
172
136
isCached = false ;
173
- var semanticVersions = GetElements ( ) ;
174
- return semanticVersions . ToLookup ( element => element . Tag . Commit , element => element ) ;
137
+ return GetElements ( ) . Distinct ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
175
138
} ) ;
176
139
177
140
if ( isCached )
@@ -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,41 @@ 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 readonly ConcurrentDictionary < ( string , SemanticVersionFormat ) , ILookup < ICommit , SemanticVersionWithTag > >
244
+ taggedSemanticVersionsCache = new ( ) ;
245
+
246
+ private ILookup < ICommit , SemanticVersionWithTag > GetTaggedSemanticVersions ( string ? tagPrefix , SemanticVersionFormat format )
247
+ {
248
+ tagPrefix ??= string . Empty ;
249
+
250
+ IEnumerable < SemanticVersionWithTag > GetElements ( )
251
+ {
252
+ this . log . Info ( $ "Getting tagged semantic versions. TagPrefix: { tagPrefix } and Format: { format } ") ;
253
+
254
+ foreach ( var tag in this . gitRepository . Tags )
255
+ {
256
+ if ( SemanticVersion . TryParse ( tag . Name . Friendly , tagPrefix , out var semanticVersion , format ) )
257
+ {
258
+ yield return new SemanticVersionWithTag ( semanticVersion , tag ) ;
259
+ }
260
+ }
261
+ }
262
+
263
+ bool isCached = true ;
264
+ var result = taggedSemanticVersionsCache . GetOrAdd ( new ( tagPrefix , format ) , _ =>
265
+ {
266
+ isCached = false ;
267
+ return GetElements ( ) . ToLookup ( element => element . Tag . Commit , element => element ) ;
268
+ } ) ;
269
+
270
+ if ( isCached )
271
+ {
272
+ this . log . Debug ( $ "Returning cached tagged semantic versions. TagPrefix: { tagPrefix } and Format: { format } ") ;
273
+ }
274
+
275
+ return result ;
278
276
}
279
277
}
0 commit comments