comparison rust/hg-core/src/utils/files.rs @ 44998:26114bd6ec60

rust: do a clippy pass This is the result of running `cargo clippy` on hg-core/hg-cpython and fixing the lints that do not require too much code churn (and would warrant a separate commit/complete refactor) and only come from our code (a lot of warnings in hg-cpython come from `rust-cpython`). Most of those were good lints, two of them was the linter not being smart enough (or compiler to get up to `clippy`'s level depending on how you see it). Maybe in the future we could have `clippy` be part of the CI. Differential Revision: https://phab.mercurial-scm.org/D8635
author Rapha?l Gom?s <rgomes@octobus.net>
date Mon, 15 Jun 2020 18:26:40 +0200
parents 07d9fd6097e6
children 1b3197047f5c
comparison
equal deleted inserted replaced
44997:ef8dcee272ac 44998:26114bd6ec60
96 /// 96 ///
97 /// The path is separated by '/', and must not start with '/'. 97 /// The path is separated by '/', and must not start with '/'.
98 /// 98 ///
99 /// The path itself isn't included unless it is b"" (meaning the root 99 /// The path itself isn't included unless it is b"" (meaning the root
100 /// directory.) 100 /// directory.)
101 pub fn find_dirs<'a>(path: &'a HgPath) -> Ancestors<'a> { 101 pub fn find_dirs(path: &HgPath) -> Ancestors {
102 let mut dirs = Ancestors { next: Some(path) }; 102 let mut dirs = Ancestors { next: Some(path) };
103 if !path.is_empty() { 103 if !path.is_empty() {
104 dirs.next(); // skip itself 104 dirs.next(); // skip itself
105 } 105 }
106 dirs 106 dirs
111 /// 111 ///
112 /// The path is separated by '/', and must not start with '/'. 112 /// The path is separated by '/', and must not start with '/'.
113 /// 113 ///
114 /// The path itself isn't included unless it is b"" (meaning the root 114 /// The path itself isn't included unless it is b"" (meaning the root
115 /// directory.) 115 /// directory.)
116 pub(crate) fn find_dirs_with_base<'a>( 116 pub(crate) fn find_dirs_with_base(path: &HgPath) -> AncestorsWithBase {
117 path: &'a HgPath,
118 ) -> AncestorsWithBase<'a> {
119 let mut dirs = AncestorsWithBase { 117 let mut dirs = AncestorsWithBase {
120 next: Some((path, HgPath::new(b""))), 118 next: Some((path, HgPath::new(b""))),
121 }; 119 };
122 if !path.is_empty() { 120 if !path.is_empty() {
123 dirs.next(); // skip itself 121 dirs.next(); // skip itself
212 }; 210 };
213 let auditor = PathAuditor::new(&root); 211 let auditor = PathAuditor::new(&root);
214 if name != root && name.starts_with(&root) { 212 if name != root && name.starts_with(&root) {
215 let name = name.strip_prefix(&root).unwrap(); 213 let name = name.strip_prefix(&root).unwrap();
216 auditor.audit_path(path_to_hg_path_buf(name)?)?; 214 auditor.audit_path(path_to_hg_path_buf(name)?)?;
217 return Ok(name.to_owned()); 215 Ok(name.to_owned())
218 } else if name == root { 216 } else if name == root {
219 return Ok("".into()); 217 Ok("".into())
220 } else { 218 } else {
221 // Determine whether `name' is in the hierarchy at or beneath `root', 219 // Determine whether `name' is in the hierarchy at or beneath `root',
222 // by iterating name=name.parent() until it returns `None` (can't 220 // by iterating name=name.parent() until it returns `None` (can't
223 // check name == '/', because that doesn't work on windows). 221 // check name == '/', because that doesn't work on windows).
224 let mut name = name.deref(); 222 let mut name = name.deref();