@@ -16,6 +16,7 @@ internal class IncrementStrategyFinder : IIncrementStrategyFinder
16
16
private readonly Dictionary < string , VersionField ? > commitIncrementCache = new ( ) ;
17
17
private readonly Dictionary < string , Dictionary < string , int > > headCommitsMapCache = new ( ) ;
18
18
private readonly Dictionary < string , ICommit [ ] > headCommitsCache = new ( ) ;
19
+ private readonly Lazy < IReadOnlySet < string ? > > tagsShaCache ;
19
20
20
21
private static readonly Regex DefaultMajorPatternRegex = new ( DefaultMajorPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
21
22
private static readonly Regex DefaultMinorPatternRegex = new ( DefaultMinorPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
@@ -24,7 +25,11 @@ internal class IncrementStrategyFinder : IIncrementStrategyFinder
24
25
25
26
private readonly IGitRepository repository ;
26
27
27
- public IncrementStrategyFinder ( IGitRepository repository ) => this . repository = repository . NotNull ( ) ;
28
+ public IncrementStrategyFinder ( IGitRepository repository )
29
+ {
30
+ this . repository = repository . NotNull ( ) ;
31
+ this . tagsShaCache = new Lazy < IReadOnlySet < string ? > > ( ReadRepositoryTagsSha ) ;
32
+ }
28
33
29
34
public VersionField DetermineIncrementedField ( ICommit ? currentCommit , BaseVersion baseVersion , EffectiveConfiguration configuration )
30
35
{
@@ -79,12 +84,10 @@ public VersionField DetermineIncrementedField(ICommit? currentCommit, BaseVersio
79
84
}
80
85
81
86
var commits = GetIntermediateCommits ( baseCommit , currentCommit ) ;
82
-
83
87
// consider commit messages since latest tag only (see #3071)
84
- var tags = new HashSet < string ? > ( repository . Tags . Select ( t => t . TargetSha ) ) ;
85
88
commits = commits
86
89
. Reverse ( )
87
- . TakeWhile ( x => ! tags . Contains ( x . Sha ) )
90
+ . TakeWhile ( x => ! this . tagsShaCache . Value . Contains ( x . Sha ) )
88
91
. Reverse ( ) ;
89
92
90
93
if ( configuration . CommitMessageIncrementing == CommitMessageIncrementMode . MergeMessageOnly )
@@ -101,6 +104,8 @@ public VersionField DetermineIncrementedField(ICommit? currentCommit, BaseVersio
101
104
) ;
102
105
}
103
106
107
+ private IReadOnlySet < string ? > ReadRepositoryTagsSha ( ) => repository . Tags . Select ( t => t . TargetSha ) . ToHashSet ( ) ;
108
+
104
109
private static Regex TryGetRegexOrDefault ( string ? messageRegex , Regex defaultRegex ) =>
105
110
messageRegex == null
106
111
? defaultRegex
0 commit comments