11using GitVersion . Extensions ;
22using GitVersion . Git ;
3- using LibGit2Sharp ;
43
54namespace GitVersion . VersionCalculation ;
65
76internal class PathFilter ( IGitRepository repository , GitVersionContext context , IEnumerable < string > paths , PathFilter . PathFilterMode mode = PathFilter . PathFilterMode . Inclusive ) : IVersionFilter
87{
9- private readonly static Dictionary < string , Patch > patchsCache = [ ] ;
10-
118 public enum PathFilterMode { Inclusive = 0 , Exclusive = 1 }
129
1310 private readonly IEnumerable < string > paths = paths . NotNull ( ) ;
@@ -24,44 +21,28 @@ public bool Exclude(IBaseVersion baseVersion, out string? reason)
2421 return Exclude ( baseVersion . BaseVersionSource , out reason ) ;
2522 }
2623
27- public bool Exclude ( ICommit ? localCommit , out string ? reason )
24+ public bool Exclude ( ICommit ? commit , out string ? reason )
2825 {
29- localCommit . NotNull ( ) ;
30- var commit = repository . InnerCommits . First ( c => c . Sha == localCommit . Sha ) ;
31-
26+ commit . NotNull ( ) ;
3227 reason = null ;
3328
34- var match = new System . Text . RegularExpressions . Regex ( $ "^({ context . Configuration . TagPrefixPattern } ).*$",
35- System . Text . RegularExpressions . RegexOptions . Compiled ) ;
36-
3729 if ( commit != null )
3830 {
39- Patch ? patch = null ;
40- if ( ! patchsCache . ContainsKey ( commit . Sha ) )
41- {
42- if ( ! repository . InnerTags . Any ( t => t . Target . Sha == commit . Sha && match . IsMatch ( t . FriendlyName ) ) )
43- {
44- Tree commitTree = commit . Tree ; // Main Tree
45- Tree ? parentCommitTree = commit . Parents . FirstOrDefault ( ) ? . Tree ; // Secondary Tree
46- patch = repository . InnerDiff . Compare < Patch > ( parentCommitTree , commitTree ) ; // Difference
47- }
48- patchsCache [ commit . Sha ] = patch ;
49- }
31+ var patchPaths = repository . FindPatchPaths ( commit , context . Configuration . TagPrefixPattern ) ;
5032
51- patch = patchsCache [ commit . Sha ] ;
52- if ( patch != null )
33+ if ( patchPaths != null )
5334 {
5435 switch ( mode )
5536 {
5637 case PathFilterMode . Inclusive :
57- if ( ! paths . Any ( path => patch . Any ( p => p . Path . StartsWith ( path , StringComparison . OrdinalIgnoreCase ) ) ) )
38+ if ( ! paths . Any ( path => patchPaths . Any ( p => p . StartsWith ( path , StringComparison . OrdinalIgnoreCase ) ) ) )
5839 {
5940 reason = "Source was ignored due to commit path is not present" ;
6041 return true ;
6142 }
6243 break ;
6344 case PathFilterMode . Exclusive :
64- if ( paths . Any ( path => patch . All ( p => p . Path . StartsWith ( path , StringComparison . OrdinalIgnoreCase ) ) ) )
45+ if ( paths . Any ( path => patchPaths . All ( p => p . StartsWith ( path , StringComparison . OrdinalIgnoreCase ) ) ) )
6546 {
6647 reason = "Source was ignored due to commit path excluded" ;
6748 return true ;
0 commit comments