1
- using System . Text . RegularExpressions ;
1
+ using System . Collections . Concurrent ;
2
2
using GitVersion . Extensions ;
3
3
using GitVersion . Helpers ;
4
4
using LibGit2Sharp ;
@@ -8,7 +8,7 @@ namespace GitVersion.Git;
8
8
internal sealed partial class GitRepository
9
9
{
10
10
private Lazy < IRepository > ? repositoryLazy ;
11
- private readonly Dictionary < string , Patch > patchCache = [ ] ;
11
+ private readonly ConcurrentDictionary < string , IReadOnlyList < string > ? > patchPathsCache = new ( ) ;
12
12
13
13
private IRepository RepositoryInstance
14
14
{
@@ -55,28 +55,37 @@ public void DiscoverRepository(string? gitDirectory)
55
55
} ) ;
56
56
}
57
57
58
- public IEnumerable < string > ? FindPatchPaths ( ICommit commit , string ? tagPrefix )
58
+ public IReadOnlyList < string > ? FindPatchPaths ( ICommit commit , string ? tagPrefix )
59
59
{
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 ) ;
63
61
64
- if ( ! this . patchCache . ContainsKey ( commit . Sha ) )
62
+ return patchPathsCache . GetOrAdd ( commit . Sha , commitSha =>
65
63
{
66
- if ( ! this . RepositoryInstance . Tags . Any ( t => t . Target . Sha == commit . Sha && match . IsMatch ( t . FriendlyName ) ) )
64
+ if ( PatchPathsNeedsToBeDetermined ( commitSha , tagPrefix ) )
67
65
{
66
+ var innerCommit = this . RepositoryInstance . Commits . First ( c => c . Sha == commitSha ) ;
68
67
Tree commitTree = innerCommit . Tree ; // Main Tree
69
68
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 ( ) ;
72
71
}
73
- }
74
- else
72
+ return null ;
73
+ } ) ;
74
+ }
75
+
76
+ private bool PatchPathsNeedsToBeDetermined ( string commitSha , string ? tagPrefix )
77
+ {
78
+ if ( ! string . IsNullOrEmpty ( tagPrefix ) )
75
79
{
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
+ }
77
87
}
78
-
79
- return patch ? . Select ( p => p . Path ) ;
88
+ return true ;
80
89
}
81
90
82
91
public int UncommittedChangesCount ( )
0 commit comments