1- using System . Text . RegularExpressions ;
1+ using System . Collections . Concurrent ;
22using GitVersion . Extensions ;
33using GitVersion . Helpers ;
44using LibGit2Sharp ;
@@ -8,7 +8,7 @@ namespace GitVersion.Git;
88internal sealed partial class GitRepository
99{
1010 private Lazy < IRepository > ? repositoryLazy ;
11- private readonly Dictionary < string , Patch > patchCache = [ ] ;
11+ private readonly ConcurrentDictionary < string , IReadOnlyList < string > ? > patchPathsCache = new ( ) ;
1212
1313 private IRepository RepositoryInstance
1414 {
@@ -55,28 +55,37 @@ public void DiscoverRepository(string? gitDirectory)
5555 } ) ;
5656 }
5757
58- public IEnumerable < string > ? FindPatchPaths ( ICommit commit , string ? tagPrefix )
58+ public IReadOnlyList < string > ? FindPatchPaths ( ICommit commit , string ? tagPrefix )
5959 {
60- Patch ? patch = null ;
61- var innerCommit = this . RepositoryInstance . Commits . First ( c => c . Sha == commit . Sha ) ;
62- var match = new Regex ( $ "^({ tagPrefix ?? "" } ).*$", RegexOptions . Compiled ) ;
60+ ArgumentNullException . ThrowIfNull ( commit ) ;
6361
64- if ( ! this . patchCache . ContainsKey ( commit . Sha ) )
62+ return patchPathsCache . GetOrAdd ( commit . Sha , commitSha =>
6563 {
66- if ( ! this . RepositoryInstance . Tags . Any ( t => t . Target . Sha == commit . Sha && match . IsMatch ( t . FriendlyName ) ) )
64+ if ( PatchPathsNeedsToBeDetermined ( commitSha , tagPrefix ) )
6765 {
66+ var innerCommit = this . RepositoryInstance . Commits . First ( c => c . Sha == commitSha ) ;
6867 Tree commitTree = innerCommit . Tree ; // Main Tree
6968 Tree ? parentCommitTree = innerCommit . Parents . FirstOrDefault ( ) ? . Tree ; // Secondary Tree
70- patch = this . RepositoryInstance . Diff . Compare < Patch > ( parentCommitTree , commitTree ) ; // Difference
71- this . patchCache [ commit . Sha ] = patch ;
69+ Patch patch = this . RepositoryInstance . Diff . Compare < Patch > ( parentCommitTree , commitTree ) ; // Difference
70+ return patch . Select ( element => element . Path ) . ToList ( ) ;
7271 }
73- }
74- else
72+ return null ;
73+ } ) ;
74+ }
75+
76+ private bool PatchPathsNeedsToBeDetermined ( string commitSha , string ? tagPrefix )
77+ {
78+ if ( ! string . IsNullOrEmpty ( tagPrefix ) )
7579 {
76- patch = this . patchCache [ commit . Sha ] ;
80+ foreach ( var tag in this . RepositoryInstance . Tags . Where ( element => element . Target . Sha == commitSha ) )
81+ {
82+ if ( tag . FriendlyName . StartsWith ( tagPrefix , StringComparison . InvariantCulture ) )
83+ {
84+ return false ;
85+ }
86+ }
7787 }
78-
79- return patch ? . Select ( p => p . Path ) ;
88+ return true ;
8089 }
8190
8291 public int UncommittedChangesCount ( )
0 commit comments