##// END OF EJS Templates
rust-status: return a ParallelIterator instead of a Vec from stat_dmap_entries...
Raphaël Gomès -
r44001:75fe6e71 default
parent child Browse files
Show More
@@ -113,53 +113,48 b' fn dispatch_missing(state: EntryState) -'
113 /// the relevant collections.
113 /// the relevant collections.
114 fn stat_dmap_entries(
114 fn stat_dmap_entries(
115 dmap: &DirstateMap,
115 dmap: &DirstateMap,
116 root_dir: impl AsRef<Path> + Sync,
116 root_dir: impl AsRef<Path> + Sync + Send,
117 check_exec: bool,
117 check_exec: bool,
118 list_clean: bool,
118 list_clean: bool,
119 last_normal_time: i64,
119 last_normal_time: i64,
120 ) -> std::io::Result<Vec<(&HgPath, Dispatch)>> {
120 ) -> impl ParallelIterator<Item = std::io::Result<(&HgPath, Dispatch)>> {
121 dmap.par_iter()
121 dmap.par_iter().map(move |(filename, entry)| {
122 .filter_map(
122 let filename: &HgPath = filename;
123 // Getting file metadata is costly, so we don't do it if the
123 let filename_as_path = hg_path_to_path_buf(filename)?;
124 // file is already present in the results, hence `filter_map`
124 let meta = root_dir.as_ref().join(filename_as_path).symlink_metadata();
125 |(filename, entry)| -> Option<
126 std::io::Result<(&HgPath, Dispatch)>
127 > {
128 let meta = match hg_path_to_path_buf(filename) {
129 Ok(p) => root_dir.as_ref().join(p).symlink_metadata(),
130 Err(e) => return Some(Err(e.into())),
131 };
132
125
133 Some(match meta {
126 match meta {
134 Ok(ref m)
127 Ok(ref m)
135 if !(m.file_type().is_file()
128 if !(m.file_type().is_file()
136 || m.file_type().is_symlink()) =>
129 || m.file_type().is_symlink()) =>
137 {
130 {
138 Ok((filename, dispatch_missing(entry.state)))
131 Ok((filename, dispatch_missing(entry.state)))
139 }
132 }
140 Ok(m) => Ok((filename, dispatch_found(
133 Ok(m) => Ok((
141 filename,
134 filename,
142 *entry,
135 dispatch_found(
143 HgMetadata::from_metadata(m),
136 filename,
144 &dmap.copy_map,
137 *entry,
145 check_exec,
138 HgMetadata::from_metadata(m),
146 list_clean,
139 &dmap.copy_map,
147 last_normal_time))),
140 check_exec,
148 Err(ref e)
141 list_clean,
149 if e.kind() == std::io::ErrorKind::NotFound
142 last_normal_time,
150 || e.raw_os_error() == Some(20) =>
143 ),
151 {
144 )),
152 // Rust does not yet have an `ErrorKind` for
145 Err(ref e)
153 // `NotADirectory` (errno 20)
146 if e.kind() == std::io::ErrorKind::NotFound
154 // It happens if the dirstate contains `foo/bar` and
147 || e.raw_os_error() == Some(20) =>
155 // foo is not a directory
148 {
156 Ok((filename, dispatch_missing(entry.state)))
149 // Rust does not yet have an `ErrorKind` for
157 }
150 // `NotADirectory` (errno 20)
158 Err(e) => Err(e),
151 // It happens if the dirstate contains `foo/bar` and
159 })
152 // foo is not a directory
160 },
153 Ok((filename, dispatch_missing(entry.state)))
161 )
154 }
162 .collect()
155 Err(e) => Err(e),
156 }
157 })
163 }
158 }
164
159
165 pub struct StatusResult<'a> {
160 pub struct StatusResult<'a> {
@@ -208,18 +203,19 b' fn build_response('
208
203
209 pub fn status(
204 pub fn status(
210 dmap: &DirstateMap,
205 dmap: &DirstateMap,
211 root_dir: impl AsRef<Path> + Sync + Copy,
206 root_dir: impl AsRef<Path> + Sync + Send + Copy,
212 list_clean: bool,
207 list_clean: bool,
213 last_normal_time: i64,
208 last_normal_time: i64,
214 check_exec: bool,
209 check_exec: bool,
215 ) -> std::io::Result<(Vec<&HgPath>, StatusResult)> {
210 ) -> std::io::Result<(Vec<&HgPath>, StatusResult)> {
216 let results = stat_dmap_entries(
211 let results: std::io::Result<_> = stat_dmap_entries(
217 &dmap,
212 &dmap,
218 root_dir,
213 root_dir,
219 check_exec,
214 check_exec,
220 list_clean,
215 list_clean,
221 last_normal_time,
216 last_normal_time,
222 )?;
217 )
218 .collect();
223
219
224 Ok(build_response(results))
220 Ok(build_response(results?))
225 }
221 }
General Comments 0
You need to be logged in to leave comments. Login now