Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHGd5407b2e7689: rust: leverage improved match ergonomics
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
hg-reviewers |
No Linters Available |
No Unit Test Coverage |
Note: this only works on 1.39+ (@martinvonz, you were wondering)
Path | Packages | |||
---|---|---|---|---|
M | rust/hg-core/src/dirstate/status.rs (8 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
d5d81c0a18d1 | 73345b4adf3c | Raphaël Gomès | Oct 1 2020, 3:49 AM |
}; | }; | ||||
let filename_as_path = hg_path_to_path_buf(&filename)?; | let filename_as_path = hg_path_to_path_buf(&filename)?; | ||||
let meta = self | let meta = self | ||||
.root_dir | .root_dir | ||||
.join(filename_as_path) | .join(filename_as_path) | ||||
.symlink_metadata(); | .symlink_metadata(); | ||||
match meta { | match meta { | ||||
Ok(ref m) | Ok(m) | ||||
if !(m.file_type().is_file() | if !(m.file_type().is_file() | ||||
|| m.file_type().is_symlink()) => | || m.file_type().is_symlink()) => | ||||
{ | { | ||||
Ok(( | Ok(( | ||||
Cow::Owned(filename), | Cow::Owned(filename), | ||||
dispatch_missing(entry.state), | dispatch_missing(entry.state), | ||||
)) | )) | ||||
} | } | ||||
Ok(m) => { | Ok(m) => { | ||||
let dispatch = dispatch_found( | let dispatch = dispatch_found( | ||||
&filename, | &filename, | ||||
entry, | entry, | ||||
HgMetadata::from_metadata(m), | HgMetadata::from_metadata(m), | ||||
&self.dmap.copy_map, | &self.dmap.copy_map, | ||||
self.options, | self.options, | ||||
); | ); | ||||
Ok((Cow::Owned(filename), dispatch)) | Ok((Cow::Owned(filename), dispatch)) | ||||
} | } | ||||
Err(ref e) | Err(e) | ||||
if e.kind() == ErrorKind::NotFound | if e.kind() == ErrorKind::NotFound | ||||
|| e.raw_os_error() == Some(20) => | || e.raw_os_error() == Some(20) => | ||||
{ | { | ||||
// Rust does not yet have an `ErrorKind` for | // Rust does not yet have an `ErrorKind` for | ||||
// `NotADirectory` (errno 20) | // `NotADirectory` (errno 20) | ||||
// It happens if the dirstate contains `foo/bar` | // It happens if the dirstate contains `foo/bar` | ||||
// and foo is not a | // and foo is not a | ||||
// directory | // directory | ||||
pub fn extend_from_dmap(&self, results: &mut Vec<DispatchedPath<'a>>) { | pub fn extend_from_dmap(&self, results: &mut Vec<DispatchedPath<'a>>) { | ||||
results.par_extend(self.dmap.par_iter().flat_map( | results.par_extend(self.dmap.par_iter().flat_map( | ||||
move |(filename, entry)| { | move |(filename, entry)| { | ||||
let filename: &HgPath = filename; | let filename: &HgPath = filename; | ||||
let filename_as_path = hg_path_to_path_buf(filename)?; | let filename_as_path = hg_path_to_path_buf(filename)?; | ||||
let meta = | let meta = | ||||
self.root_dir.join(filename_as_path).symlink_metadata(); | self.root_dir.join(filename_as_path).symlink_metadata(); | ||||
match meta { | match meta { | ||||
Ok(ref m) | Ok(m) | ||||
if !(m.file_type().is_file() | if !(m.file_type().is_file() | ||||
|| m.file_type().is_symlink()) => | || m.file_type().is_symlink()) => | ||||
{ | { | ||||
Ok(( | Ok(( | ||||
Cow::Borrowed(filename), | Cow::Borrowed(filename), | ||||
dispatch_missing(entry.state), | dispatch_missing(entry.state), | ||||
)) | )) | ||||
} | } | ||||
Ok(m) => Ok(( | Ok(m) => Ok(( | ||||
Cow::Borrowed(filename), | Cow::Borrowed(filename), | ||||
dispatch_found( | dispatch_found( | ||||
filename, | filename, | ||||
*entry, | *entry, | ||||
HgMetadata::from_metadata(m), | HgMetadata::from_metadata(m), | ||||
&self.dmap.copy_map, | &self.dmap.copy_map, | ||||
self.options, | self.options, | ||||
), | ), | ||||
)), | )), | ||||
Err(ref e) | Err(e) | ||||
if e.kind() == ErrorKind::NotFound | if e.kind() == ErrorKind::NotFound | ||||
|| e.raw_os_error() == Some(20) => | || e.raw_os_error() == Some(20) => | ||||
{ | { | ||||
// Rust does not yet have an `ErrorKind` for | // Rust does not yet have an `ErrorKind` for | ||||
// `NotADirectory` (errno 20) | // `NotADirectory` (errno 20) | ||||
// It happens if the dirstate contains `foo/bar` | // It happens if the dirstate contains `foo/bar` | ||||
// and foo is not a | // and foo is not a | ||||
// directory | // directory |