Resolve a hash prefix to a full hash.
(
&self,
repo: &Repository,
view_name: &str,
prefix: &str,
)
| 201 | |
| 202 | /// Resolve a hash prefix to a full hash. |
| 203 | fn resolve_hash_prefix( |
| 204 | &self, |
| 205 | repo: &Repository, |
| 206 | view_name: &str, |
| 207 | prefix: &str, |
| 208 | ) -> CliResult<(Hash, Option<u64>)> { |
| 209 | // Search for matching changes |
| 210 | let mut matches: Vec<Hash> = Vec::new(); |
| 211 | |
| 212 | for result in repo.iter_changes() { |
| 213 | let hash = result.map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?; |
| 214 | let hash_str = hash.to_base32(); |
| 215 | if hash_str.starts_with(prefix) { |
| 216 | matches.push(hash); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | match matches.len() { |
| 221 | 0 => Err(CliError::ChangeNotFound { |
| 222 | hash: prefix.to_string(), |
| 223 | }), |
| 224 | 1 => { |
| 225 | let hash = matches[0]; |
| 226 | let seq = self.find_sequence_for_hash(repo, view_name, &hash)?; |
| 227 | Ok((hash, seq)) |
| 228 | } |
| 229 | _ => { |
| 230 | // Format the matches for display in the error message |
| 231 | let match_list: Vec<String> = matches.iter().map(|h| h.to_base32()).collect(); |
| 232 | Err(CliError::AmbiguousHash { |
| 233 | hash: format!("{} (matches: {})", prefix, match_list.join(", ")), |
| 234 | }) |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /// Resolve a sequence number to a hash. |
| 240 | fn resolve_sequence(&self, repo: &Repository, view_name: &str, seq: u64) -> CliResult<Hash> { |
no test coverage detected