1
- use crate :: store:: file;
2
- use bstr:: { BString , ByteSlice } ;
1
+ use crate :: { mutable :: FullName , store:: file} ;
2
+ use bstr:: ByteSlice ;
3
3
use git_features:: fs:: walkdir:: DirEntryIter ;
4
4
use os_str_bytes:: OsStrBytes ;
5
5
use std:: {
@@ -11,31 +11,20 @@ use std::{
11
11
pub ( in crate :: store:: file) struct SortedLoosePaths {
12
12
base : PathBuf ,
13
13
file_walk : DirEntryIter ,
14
- mode : LoosePathsMode ,
15
- }
16
-
17
- enum LoosePathsMode {
18
- Paths ,
19
- PathsAndNames ,
20
14
}
21
15
22
16
impl SortedLoosePaths {
23
- pub fn at_root ( path : impl AsRef < Path > , base : impl Into < PathBuf > ) -> Self {
24
- Self :: new ( path. as_ref ( ) , base. into ( ) , LoosePathsMode :: Paths )
25
- }
26
-
27
17
pub fn at_root_with_names ( path : impl AsRef < Path > , base : impl Into < PathBuf > ) -> Self {
28
- Self :: new ( path. as_ref ( ) , base. into ( ) , LoosePathsMode :: PathsAndNames )
29
- }
30
-
31
- fn new ( path : & Path , base : PathBuf , mode : LoosePathsMode ) -> Self {
32
18
let file_walk = git_features:: fs:: walkdir_sorted_new ( path) . into_iter ( ) ;
33
- SortedLoosePaths { base, file_walk, mode }
19
+ SortedLoosePaths {
20
+ base : base. into ( ) ,
21
+ file_walk,
22
+ }
34
23
}
35
24
}
36
25
37
26
impl Iterator for SortedLoosePaths {
38
- type Item = std:: io:: Result < ( PathBuf , Option < BString > ) > ;
27
+ type Item = std:: io:: Result < ( PathBuf , FullName ) > ;
39
28
40
29
fn next ( & mut self ) -> Option < Self :: Item > {
41
30
while let Some ( entry) = self . file_walk . next ( ) {
@@ -52,15 +41,11 @@ impl Iterator for SortedLoosePaths {
52
41
#[ cfg( windows) ]
53
42
let full_name: Vec < u8 > = full_name. into_owned ( ) . replace ( b"\\ " , b"/" ) ;
54
43
55
- use LoosePathsMode :: * ;
56
44
if git_validate:: reference:: name_partial ( full_name. as_bstr ( ) ) . is_ok ( ) {
57
- let name = match self . mode {
58
- Paths => None ,
59
- #[ cfg( not( windows) ) ]
60
- PathsAndNames => Some ( full_name. into_owned ( ) . into ( ) ) ,
61
- #[ cfg( windows) ]
62
- PathsAndNames => Some ( full_name. into ( ) ) ,
63
- } ;
45
+ #[ cfg( not( windows) ) ]
46
+ let name = FullName ( full_name. into_owned ( ) . into ( ) ) ;
47
+ #[ cfg( windows) ]
48
+ let name = FullName ( full_name. into ( ) ) ;
64
49
return Some ( Ok ( ( full_path, name) ) ) ;
65
50
} else {
66
51
continue ;
@@ -86,7 +71,7 @@ impl<'a> Loose<'a> {
86
71
pub fn at_root ( store : & ' a file:: Store , root : impl AsRef < Path > , base : impl Into < PathBuf > ) -> Self {
87
72
Loose {
88
73
parent : store,
89
- ref_paths : SortedLoosePaths :: at_root ( root, base) ,
74
+ ref_paths : SortedLoosePaths :: at_root_with_names ( root, base) ,
90
75
buf : Vec :: new ( ) ,
91
76
}
92
77
}
@@ -97,26 +82,25 @@ impl<'a> Iterator for Loose<'a> {
97
82
98
83
fn next ( & mut self ) -> Option < Self :: Item > {
99
84
self . ref_paths . next ( ) . map ( |res| {
100
- res. map_err ( loose:: Error :: Traversal )
101
- . and_then ( |( validated_path, _name) | {
102
- std:: fs:: File :: open ( & validated_path)
103
- . and_then ( |mut f| {
104
- self . buf . clear ( ) ;
105
- f. read_to_end ( & mut self . buf )
106
- } )
107
- . map_err ( loose:: Error :: ReadFileContents )
108
- . and_then ( |_| {
109
- let relative_path = validated_path
110
- . strip_prefix ( & self . ref_paths . base )
111
- . expect ( "root contains path" ) ;
112
- file:: Reference :: try_from_path ( self . parent , relative_path, & self . buf ) . map_err ( |err| {
113
- loose:: Error :: ReferenceCreation {
114
- err,
115
- relative_path : relative_path. into ( ) ,
116
- }
117
- } )
85
+ res. map_err ( loose:: Error :: Traversal ) . and_then ( |( validated_path, name) | {
86
+ std:: fs:: File :: open ( & validated_path)
87
+ . and_then ( |mut f| {
88
+ self . buf . clear ( ) ;
89
+ f. read_to_end ( & mut self . buf )
90
+ } )
91
+ . map_err ( loose:: Error :: ReadFileContents )
92
+ . and_then ( |_| {
93
+ let relative_path = validated_path
94
+ . strip_prefix ( & self . ref_paths . base )
95
+ . expect ( "root contains path" ) ;
96
+ file:: Reference :: try_from_path ( self . parent , name, & self . buf ) . map_err ( |err| {
97
+ loose:: Error :: ReferenceCreation {
98
+ err,
99
+ relative_path : relative_path. into ( ) ,
100
+ }
118
101
} )
119
- } )
102
+ } )
103
+ } )
120
104
} )
121
105
}
122
106
}
0 commit comments