@@ -31,6 +31,21 @@ impl Search {
31
31
is_dir : Option < bool > ,
32
32
attributes : & mut dyn FnMut ( & BStr , Case , bool , & mut gix_attributes:: search:: Outcome ) -> bool ,
33
33
) -> Option < Match < ' _ > > {
34
+ static MATCH_ALL_STAND_IN : Pattern = Pattern {
35
+ path : BString :: new ( Vec :: new ( ) ) ,
36
+ signature : MagicSignature :: empty ( ) ,
37
+ search_mode : SearchMode :: ShellGlob ,
38
+ attributes : Vec :: new ( ) ,
39
+ prefix_len : 0 ,
40
+ nil : true ,
41
+ } ;
42
+ if relative_path. is_empty ( ) {
43
+ return Some ( Match {
44
+ pattern : & MATCH_ALL_STAND_IN ,
45
+ sequence_number : 0 ,
46
+ kind : Always ,
47
+ } ) ;
48
+ }
34
49
let basename_not_important = None ;
35
50
if relative_path
36
51
. get ( ..self . common_prefix_len )
@@ -106,14 +121,6 @@ impl Search {
106
121
} ) ;
107
122
108
123
if res. is_none ( ) && self . all_patterns_are_excluded {
109
- static MATCH_ALL_STAND_IN : Pattern = Pattern {
110
- path : BString :: new ( Vec :: new ( ) ) ,
111
- signature : MagicSignature :: empty ( ) ,
112
- search_mode : SearchMode :: ShellGlob ,
113
- attributes : Vec :: new ( ) ,
114
- prefix_len : 0 ,
115
- nil : true ,
116
- } ;
117
124
Some ( Match {
118
125
pattern : & MATCH_ALL_STAND_IN ,
119
126
sequence_number : patterns_len,
@@ -133,7 +140,7 @@ impl Search {
133
140
/// is ignored.
134
141
/// Returns `false` if this pathspec has no chance of ever matching `relative_path`.
135
142
pub fn can_match_relative_path ( & self , relative_path : & BStr , is_dir : Option < bool > ) -> bool {
136
- if self . patterns . is_empty ( ) {
143
+ if self . patterns . is_empty ( ) || relative_path . is_empty ( ) {
137
144
return true ;
138
145
}
139
146
let common_prefix_len = self . common_prefix_len . min ( relative_path. len ( ) ) ;
@@ -194,7 +201,7 @@ impl Search {
194
201
/// When `leading` is `true`, then `d` matches `d/d` as well. Thus, `relative_path` must may be
195
202
/// partially included in `pathspec`, otherwise it has to be fully included.
196
203
pub fn directory_matches_prefix ( & self , relative_path : & BStr , leading : bool ) -> bool {
197
- if self . patterns . is_empty ( ) {
204
+ if self . patterns . is_empty ( ) || relative_path . is_empty ( ) {
198
205
return true ;
199
206
}
200
207
let common_prefix_len = self . common_prefix_len . min ( relative_path. len ( ) ) ;
0 commit comments