@@ -105,18 +105,25 @@ where
105
105
/// multi-threaded walker will be created.
106
106
pub fn new (
107
107
root : PathBuf ,
108
+ dot_dir : String ,
108
109
matcher : M ,
109
110
include_directories : bool ,
110
111
num_threads : u8 ,
111
112
) -> Result < Self > {
112
113
let inner = match NonZeroU8 :: new ( num_threads) {
113
114
Some ( num_threads) => WalkerType :: Multi ( MultiWalker :: new (
114
115
root,
116
+ dot_dir,
115
117
matcher,
116
118
include_directories,
117
119
num_threads,
118
120
) ?) ,
119
- None => WalkerType :: Single ( SingleWalker :: new ( root, matcher, include_directories) ?) ,
121
+ None => WalkerType :: Single ( SingleWalker :: new (
122
+ root,
123
+ dot_dir,
124
+ matcher,
125
+ include_directories,
126
+ ) ?) ,
120
127
} ;
121
128
Ok ( Walker ( inner) )
122
129
}
@@ -148,13 +155,19 @@ struct SingleWalker<M> {
148
155
results : Vec < Result < WalkEntry > > ,
149
156
matcher : M ,
150
157
include_directories : bool ,
158
+ dot_dir : String ,
151
159
}
152
160
153
161
impl < M > SingleWalker < M >
154
162
where
155
163
M : Matcher ,
156
164
{
157
- pub fn new ( root : PathBuf , matcher : M , include_directories : bool ) -> Result < Self > {
165
+ pub fn new (
166
+ root : PathBuf ,
167
+ dot_dir : String ,
168
+ matcher : M ,
169
+ include_directories : bool ,
170
+ ) -> Result < Self > {
158
171
let mut dir_matches = vec ! [ ] ;
159
172
if matcher. matches_directory ( & RepoPathBuf :: new ( ) ) ? != DirectoryMatch :: Nothing {
160
173
dir_matches. push ( RepoPathBuf :: new ( ) ) ;
@@ -165,6 +178,7 @@ where
165
178
results : Vec :: new ( ) ,
166
179
matcher,
167
180
include_directories,
181
+ dot_dir,
168
182
} ;
169
183
Ok ( walker)
170
184
}
@@ -190,7 +204,7 @@ where
190
204
. push ( Ok ( WalkEntry :: File ( candidate_path, entry. metadata ( ) ?) ) ) ;
191
205
}
192
206
} else if filetype. is_dir ( ) {
193
- if filename. as_str ( ) != ".hg"
207
+ if filename. as_str ( ) != self . dot_dir
194
208
&& self
195
209
. matcher
196
210
. matches_directory ( candidate_path. as_repo_path ( ) ) ?
@@ -214,7 +228,7 @@ where
214
228
}
215
229
let abs_next_dir = self . root . join ( next_dir. as_str ( ) ) ;
216
230
// Don't process the directory if it contains a .hg directory, unless it's the root.
217
- if next_dir. is_empty ( ) || !Path :: exists ( & abs_next_dir. join ( ".hg" ) ) {
231
+ if next_dir. is_empty ( ) || !Path :: exists ( & abs_next_dir. join ( & self . dot_dir ) ) {
218
232
for entry in fs:: read_dir ( abs_next_dir)
219
233
. map_err ( |e| WalkError :: IOError ( next_dir. clone ( ) , e) ) ?
220
234
{
@@ -271,6 +285,7 @@ struct MultiWalker<M> {
271
285
result_receiver : Receiver < Result < WalkEntry > > ,
272
286
has_walked : bool ,
273
287
payload : Arc < WalkerData < M > > ,
288
+ dot_dir : String ,
274
289
}
275
290
276
291
impl < M > MultiWalker < M >
@@ -285,6 +300,7 @@ where
285
300
286
301
pub fn new (
287
302
root : PathBuf ,
303
+ dot_dir : String ,
288
304
matcher : M ,
289
305
include_directories : bool ,
290
306
num_threads : NonZeroU8 ,
@@ -308,13 +324,15 @@ where
308
324
matcher,
309
325
include_directories,
310
326
} ) ,
327
+ dot_dir,
311
328
} )
312
329
}
313
330
314
331
// WARNING: SIDE EFFECTS - if entry matches and is child directory, will push
315
332
// child and increment busy_nodes atomic.
316
333
fn match_entry_and_enqueue (
317
334
dir : & RepoPathBuf ,
335
+ dot_dir : & str ,
318
336
entry : DirEntry ,
319
337
shared_data : Arc < WalkerData < M > > ,
320
338
) -> Result < ( ) > {
@@ -339,7 +357,7 @@ where
339
357
. enqueue_result ( Ok ( WalkEntry :: File ( candidate_path, entry. metadata ( ) ?) ) ) ?;
340
358
}
341
359
} else if filetype. is_dir ( ) {
342
- if filename. as_str ( ) != ".hg"
360
+ if filename. as_str ( ) != dot_dir
343
361
&& shared_data
344
362
. matcher
345
363
. matches_directory ( candidate_path. as_repo_path ( ) ) ?
@@ -368,6 +386,7 @@ where
368
386
369
387
for _t in 0 ..self . threads . capacity ( ) {
370
388
let shared_data = self . payload . clone ( ) ;
389
+ let dot_dir = self . dot_dir . clone ( ) ;
371
390
372
391
// TODO make sure that _t is different for each thread
373
392
self . threads . push ( thread:: spawn ( move || {
@@ -392,6 +411,7 @@ where
392
411
entry. map_err ( |e| WalkError :: IOError ( dir. clone ( ) , e) ) ?;
393
412
if let Err ( e) = MultiWalker :: match_entry_and_enqueue (
394
413
& dir,
414
+ & dot_dir,
395
415
entry,
396
416
shared_data. clone ( ) ,
397
417
) {
@@ -496,7 +516,7 @@ mod tests {
496
516
let files = vec ! [ "dirA/a.txt" , "b.txt" ] ;
497
517
let root_dir = create_directory ( & directories, & files) ?;
498
518
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
499
- let walker = SingleWalker :: new ( root_path, NeverMatcher :: new ( ) , false ) ?;
519
+ let walker = SingleWalker :: new ( root_path, ".hg" . to_string ( ) , NeverMatcher :: new ( ) , false ) ?;
500
520
let walked_files: Result < Vec < _ > > = walker. collect ( ) ;
501
521
let walked_files = walked_files?;
502
522
assert ! ( walked_files. is_empty( ) ) ;
@@ -509,7 +529,7 @@ mod tests {
509
529
let files = vec ! [ "dirA/a.txt" , "dirA/b.txt" , "dirB/dirC/dirD/c.txt" ] ;
510
530
let root_dir = create_directory ( & directories, & files) ?;
511
531
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
512
- let walker = SingleWalker :: new ( root_path, AlwaysMatcher :: new ( ) , false ) ?;
532
+ let walker = SingleWalker :: new ( root_path, ".hg" . to_string ( ) , AlwaysMatcher :: new ( ) , false ) ?;
513
533
let walked_files: Result < Vec < _ > > = walker. collect ( ) ;
514
534
let walked_files = walked_files?;
515
535
assert_eq ! ( walked_files. len( ) , 3 ) ;
@@ -527,6 +547,7 @@ mod tests {
527
547
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
528
548
let walker = SingleWalker :: new (
529
549
root_path,
550
+ ".hg" . to_string ( ) ,
530
551
TreeMatcher :: from_rules ( [ "foo/bar/**" ] . iter ( ) ) . unwrap ( ) ,
531
552
false ,
532
553
) ?;
@@ -546,7 +567,7 @@ mod tests {
546
567
let files = vec ! [ "dirA/a.txt" , "dirA/b.txt" , "dirB/dirC/dirD/c.txt" ] ;
547
568
let root_dir = create_directory ( & directories, & files) ?;
548
569
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
549
- let walker = SingleWalker :: new ( root_path, AlwaysMatcher :: new ( ) , true ) ?;
570
+ let walker = SingleWalker :: new ( root_path, ".hg" . to_string ( ) , AlwaysMatcher :: new ( ) , true ) ?;
550
571
let walked_files: Result < Vec < _ > > = walker. collect ( ) ;
551
572
let walked_files = walked_files?;
552
573
// Includes root dir ""
@@ -575,6 +596,7 @@ mod tests {
575
596
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
576
597
let walker = MultiWalker :: new (
577
598
root_path,
599
+ ".hg" . to_string ( ) ,
578
600
NeverMatcher :: new ( ) ,
579
601
false ,
580
602
NonZeroU8 :: new ( 5 ) . unwrap ( ) ,
@@ -593,6 +615,7 @@ mod tests {
593
615
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
594
616
let walker = MultiWalker :: new (
595
617
root_path,
618
+ ".hg" . to_string ( ) ,
596
619
AlwaysMatcher :: new ( ) ,
597
620
false ,
598
621
NonZeroU8 :: new ( 1 ) . unwrap ( ) ,
@@ -614,6 +637,7 @@ mod tests {
614
637
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
615
638
let walker = MultiWalker :: new (
616
639
root_path,
640
+ ".hg" . to_string ( ) ,
617
641
AlwaysMatcher :: new ( ) ,
618
642
false ,
619
643
NonZeroU8 :: new ( 2 ) . unwrap ( ) ,
@@ -635,6 +659,7 @@ mod tests {
635
659
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
636
660
let walker = MultiWalker :: new (
637
661
root_path,
662
+ ".hg" . to_string ( ) ,
638
663
AlwaysMatcher :: new ( ) ,
639
664
false ,
640
665
NonZeroU8 :: new ( u8:: MAX ) . unwrap ( ) ,
@@ -656,6 +681,7 @@ mod tests {
656
681
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
657
682
let walker = MultiWalker :: new (
658
683
root_path,
684
+ ".hg" . to_string ( ) ,
659
685
TreeMatcher :: from_rules ( [ "foo/bar/**" ] . iter ( ) ) . unwrap ( ) ,
660
686
false ,
661
687
NonZeroU8 :: new ( 4 ) . unwrap ( ) ,
@@ -678,6 +704,7 @@ mod tests {
678
704
let root_path = PathBuf :: from ( root_dir. path ( ) ) ;
679
705
let walker = MultiWalker :: new (
680
706
root_path,
707
+ ".hg" . to_string ( ) ,
681
708
AlwaysMatcher :: new ( ) ,
682
709
true ,
683
710
NonZeroU8 :: new ( 2 ) . unwrap ( ) ,
0 commit comments