11use {
2- crate :: { dependency_type:: DependencyType , instance:: InstanceDescriptor , packages:: Packages } ,
3- globset:: { Glob , GlobMatcher } ,
2+ crate :: {
3+ dependency_type:: DependencyType , instance:: InstanceDescriptor , packages:: Packages ,
4+ pattern_matcher:: PatternMatcher ,
5+ } ,
46 log:: error,
57 std:: process,
68} ;
79
810#[ derive( Clone , Debug ) ]
911pub struct GroupSelector {
10- /// Glob patterns to match against the installed dependency name.
12+ /// Patterns to match against the installed dependency name.
1113 ///
1214 /// The keyword "$LOCAL" can also be used to match every locally-developed
1315 /// package used as a dependency.
14- pub include_dependencies : Vec < GlobMatcher > ,
15- pub exclude_dependencies : Vec < GlobMatcher > ,
16+ pub include_dependencies : Vec < PatternMatcher > ,
17+ pub exclude_dependencies : Vec < PatternMatcher > ,
1618 /// Named locations where dependencies should be found.
1719 ///
1820 /// Possible values:
@@ -27,10 +29,9 @@ pub struct GroupSelector {
2729 pub exclude_dependency_types : Vec < String > ,
2830 /// Optional label to describe the group.
2931 pub label : String ,
30- /// Glob patterns to match against the package name the dependency is located
31- /// in.
32- pub include_packages : Vec < GlobMatcher > ,
33- pub exclude_packages : Vec < GlobMatcher > ,
32+ /// Patterns to match against the package name the dependency is located in.
33+ pub include_packages : Vec < PatternMatcher > ,
34+ pub exclude_packages : Vec < PatternMatcher > ,
3435 /// Types of version specifier the installed dependency should have.
3536 ///
3637 /// Possible values:
@@ -66,12 +67,12 @@ impl GroupSelector {
6667 ) -> GroupSelector {
6768 let dependencies = with_resolved_keywords ( & dependencies, all_packages) ;
6869
69- let include_dependencies = create_globs ( true , & dependencies) ;
70- let exclude_dependencies = create_globs ( false , & dependencies) ;
70+ let include_dependencies = create_patterns ( true , & dependencies) ;
71+ let exclude_dependencies = create_patterns ( false , & dependencies) ;
7172 let include_dependency_types = create_identifiers ( true , & dependency_types) ;
7273 let exclude_dependency_types = create_identifiers ( false , & dependency_types) ;
73- let include_packages = create_globs ( true , & packages) ;
74- let exclude_packages = create_globs ( false , & packages) ;
74+ let include_packages = create_patterns ( true , & packages) ;
75+ let exclude_packages = create_patterns ( false , & packages) ;
7576 let include_specifier_types = create_identifiers ( true , & specifier_types) ;
7677 let exclude_specifier_types = create_identifiers ( false , & specifier_types) ;
7778
@@ -115,12 +116,12 @@ impl GroupSelector {
115116 return false ;
116117 }
117118
118- // 3. Dependencies (glob matching, more expensive )
119+ // 3. Dependencies (pattern matching, optimized for common cases )
119120 if self . has_dependency_filters && !self . matches_dependencies ( descriptor) {
120121 return false ;
121122 }
122123
123- // 4. Packages (glob matching + borrow, most expensive)
124+ // 4. Packages (pattern matching + borrow, most expensive)
124125 if self . has_package_filters && !self . matches_packages ( descriptor) {
125126 return false ;
126127 }
@@ -141,12 +142,12 @@ impl GroupSelector {
141142 fn matches_packages ( & self , descriptor : & InstanceDescriptor ) -> bool {
142143 // Cache the borrow result to avoid repeated borrow checks
143144 let package_name = & descriptor. package . borrow ( ) . name ;
144- matches_globs ( package_name, & self . include_packages , & self . exclude_packages )
145+ matches_patterns ( package_name, & self . include_packages , & self . exclude_packages )
145146 }
146147
147148 #[ inline]
148149 fn matches_dependencies ( & self , descriptor : & InstanceDescriptor ) -> bool {
149- matches_globs ( & descriptor. internal_name , & self . include_dependencies , & self . exclude_dependencies )
150+ matches_patterns ( & descriptor. internal_name , & self . include_dependencies , & self . exclude_dependencies )
150151 }
151152
152153 #[ inline]
@@ -159,26 +160,25 @@ impl GroupSelector {
159160 }
160161}
161162
162- fn create_globs ( is_include : bool , patterns : & [ String ] ) -> Vec < GlobMatcher > {
163+ fn create_patterns ( is_include : bool , patterns : & [ String ] ) -> Vec < PatternMatcher > {
163164 patterns
164165 . iter ( )
165166 . filter ( |pattern| * pattern != "**" && pattern. starts_with ( '!' ) != is_include)
166167 . map ( |pattern| {
167- Glob :: new ( & pattern. replace ( '!' , "" ) )
168- . expect ( "invalid glob pattern" )
169- . compile_matcher ( )
168+ let pattern = pattern. replace ( '!' , "" ) ;
169+ PatternMatcher :: from_pattern ( & pattern)
170170 } )
171171 . collect ( )
172172}
173173
174- fn matches_globs ( value : & str , includes : & [ GlobMatcher ] , excludes : & [ GlobMatcher ] ) -> bool {
175- let is_included = includes. is_empty ( ) || matches_any_glob ( value, includes) ;
176- let is_excluded = !excludes. is_empty ( ) && matches_any_glob ( value, excludes) ;
174+ fn matches_patterns ( value : & str , includes : & [ PatternMatcher ] , excludes : & [ PatternMatcher ] ) -> bool {
175+ let is_included = includes. is_empty ( ) || matches_any_pattern ( value, includes) ;
176+ let is_excluded = !excludes. is_empty ( ) && matches_any_pattern ( value, excludes) ;
177177 is_included && !is_excluded
178178}
179179
180- fn matches_any_glob ( value : & str , globs : & [ GlobMatcher ] ) -> bool {
181- globs . iter ( ) . any ( |glob| glob . is_match ( value) )
180+ fn matches_any_pattern ( value : & str , patterns : & [ PatternMatcher ] ) -> bool {
181+ patterns . iter ( ) . any ( |pattern| pattern . is_match ( value) )
182182}
183183
184184fn create_identifiers ( is_include : bool , patterns : & [ String ] ) -> Vec < String > {
0 commit comments