1+ using System . Collections . Concurrent ;
12using System . Diagnostics . CodeAnalysis ;
23using System . Text . RegularExpressions ;
34using GitVersion . Git ;
45
56namespace GitVersion . VersionCalculation ;
67
7- internal class PathFilter ( IEnumerable < string > paths ) : IVersionFilter
8+ internal class PathFilter ( IReadOnlyList < string > paths ) : IVersionFilter
89{
9- private readonly List < Regex > pathsRegexes = paths . Select ( path => new Regex ( path , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ) . ToList ( ) ;
10- private readonly Dictionary < string , bool > pathMatchCache = [ ] ;
10+ private readonly List < Regex > pathsRegexes = [ .. paths . Select ( path => new Regex ( path , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ) ] ;
11+ private readonly ConcurrentDictionary < string , bool > pathMatchCache = [ ] ;
1112
1213 public bool Exclude ( IBaseVersion baseVersion , [ NotNullWhen ( true ) ] out string ? reason )
1314 {
@@ -27,21 +28,18 @@ public bool Exclude(ICommit? commit, [NotNullWhen(true)] out string? reason)
2728 {
2829 var patchPaths = commit . DiffPaths ;
2930
30- if ( patchPaths != null )
31+ foreach ( var path in patchPaths )
3132 {
32- foreach ( var path in patchPaths )
33+ if ( ! pathMatchCache . TryGetValue ( path , out var isMatch ) )
3334 {
34- if ( ! pathMatchCache . TryGetValue ( path , out var isMatch ) )
35- {
36- isMatch = this . pathsRegexes . Any ( regex => regex . IsMatch ( path ) ) ;
37- pathMatchCache [ path ] = isMatch ;
38- }
39-
40- if ( isMatch )
41- {
42- reason = "Source was ignored due to commit path matching ignore regex" ;
43- return true ;
44- }
35+ isMatch = this . pathsRegexes . Any ( regex => regex . IsMatch ( path ) ) ;
36+ pathMatchCache [ path ] = isMatch ;
37+ }
38+
39+ if ( isMatch )
40+ {
41+ reason = "Source was ignored due to commit path matching ignore regex" ;
42+ return true ;
4543 }
4644 }
4745 }
0 commit comments