Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/repo.rs @ 49930:e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
All of these are simple changes that for the most part are clear improvements
and the rest are at most equivalent.
The remaining warnings have to be fixed either with a bigger refactor like for
the nested "revlog" module, or in the dependency `bytes-cast`, which we own.
This will be done sometime in the future.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 09 Jan 2023 19:18:43 +0100 |
parents | 13dfad0f9f7a |
children | 750409505286 |
comparison
equal
deleted
inserted
replaced
49929:5f1cd6839c69 | 49930:e98fd81bb151 |
---|---|
66 for ancestor in current_directory.ancestors() { | 66 for ancestor in current_directory.ancestors() { |
67 if is_dir(ancestor.join(".hg"))? { | 67 if is_dir(ancestor.join(".hg"))? { |
68 return Ok(ancestor.to_path_buf()); | 68 return Ok(ancestor.to_path_buf()); |
69 } | 69 } |
70 } | 70 } |
71 return Err(RepoError::NotFound { | 71 Err(RepoError::NotFound { |
72 at: current_directory, | 72 at: current_directory, |
73 }); | 73 }) |
74 } | 74 } |
75 | 75 |
76 /// Find a repository, either at the given path (which must contain a `.hg` | 76 /// Find a repository, either at the given path (which must contain a `.hg` |
77 /// sub-directory) or by searching the current directory and its | 77 /// sub-directory) or by searching the current directory and its |
78 /// ancestors. | 78 /// ancestors. |
85 config: &Config, | 85 config: &Config, |
86 explicit_path: Option<PathBuf>, | 86 explicit_path: Option<PathBuf>, |
87 ) -> Result<Self, RepoError> { | 87 ) -> Result<Self, RepoError> { |
88 if let Some(root) = explicit_path { | 88 if let Some(root) = explicit_path { |
89 if is_dir(root.join(".hg"))? { | 89 if is_dir(root.join(".hg"))? { |
90 Self::new_at_path(root.to_owned(), config) | 90 Self::new_at_path(root, config) |
91 } else if is_file(&root)? { | 91 } else if is_file(&root)? { |
92 Err(HgError::unsupported("bundle repository").into()) | 92 Err(HgError::unsupported("bundle repository").into()) |
93 } else { | 93 } else { |
94 Err(RepoError::NotFound { | 94 Err(RepoError::NotFound { at: root }) |
95 at: root.to_owned(), | |
96 }) | |
97 } | 95 } |
98 } else { | 96 } else { |
99 let root = Self::find_repo_root()?; | 97 let root = Self::find_repo_root()?; |
100 Self::new_at_path(root, config) | 98 Self::new_at_path(root, config) |
101 } | 99 } |
106 working_directory: PathBuf, | 104 working_directory: PathBuf, |
107 config: &Config, | 105 config: &Config, |
108 ) -> Result<Self, RepoError> { | 106 ) -> Result<Self, RepoError> { |
109 let dot_hg = working_directory.join(".hg"); | 107 let dot_hg = working_directory.join(".hg"); |
110 | 108 |
111 let mut repo_config_files = Vec::new(); | 109 let mut repo_config_files = |
112 repo_config_files.push(dot_hg.join("hgrc")); | 110 vec![dot_hg.join("hgrc"), dot_hg.join("hgrc-not-shared")]; |
113 repo_config_files.push(dot_hg.join("hgrc-not-shared")); | |
114 | 111 |
115 let hg_vfs = Vfs { base: &dot_hg }; | 112 let hg_vfs = Vfs { base: &dot_hg }; |
116 let mut reqs = requirements::load_if_exists(hg_vfs)?; | 113 let mut reqs = requirements::load_if_exists(hg_vfs)?; |
117 let relative = | 114 let relative = |
118 reqs.contains(requirements::RELATIVE_SHARED_REQUIREMENT); | 115 reqs.contains(requirements::RELATIVE_SHARED_REQUIREMENT); |
252 fn dirstate_file_contents(&self) -> Result<Vec<u8>, HgError> { | 249 fn dirstate_file_contents(&self) -> Result<Vec<u8>, HgError> { |
253 Ok(self | 250 Ok(self |
254 .hg_vfs() | 251 .hg_vfs() |
255 .read("dirstate") | 252 .read("dirstate") |
256 .io_not_found_as_none()? | 253 .io_not_found_as_none()? |
257 .unwrap_or(Vec::new())) | 254 .unwrap_or_default()) |
258 } | 255 } |
259 | 256 |
260 pub fn dirstate_parents(&self) -> Result<DirstateParents, HgError> { | 257 pub fn dirstate_parents(&self) -> Result<DirstateParents, HgError> { |
261 Ok(*self | 258 Ok(*self |
262 .dirstate_parents | 259 .dirstate_parents |
275 crate::dirstate_tree::on_disk::read_docket(&dirstate)?; | 272 crate::dirstate_tree::on_disk::read_docket(&dirstate)?; |
276 self.dirstate_data_file_uuid | 273 self.dirstate_data_file_uuid |
277 .set(Some(docket.uuid.to_owned())); | 274 .set(Some(docket.uuid.to_owned())); |
278 docket.parents() | 275 docket.parents() |
279 } else { | 276 } else { |
280 crate::dirstate::parsers::parse_dirstate_parents(&dirstate)? | 277 *crate::dirstate::parsers::parse_dirstate_parents(&dirstate)? |
281 .clone() | |
282 }; | 278 }; |
283 self.dirstate_parents.set(parents); | 279 self.dirstate_parents.set(parents); |
284 Ok(parents) | 280 Ok(parents) |
285 } | 281 } |
286 | 282 |