Resolve a hash prefix to a full hash.
(
&self,
repo: &Repository,
view_name: &str,
prefix: &str,
)
| 230 | |
| 231 | /// Resolve a hash prefix to a full hash. |
| 232 | fn resolve_hash_prefix( |
| 233 | &self, |
| 234 | repo: &Repository, |
| 235 | view_name: &str, |
| 236 | prefix: &str, |
| 237 | ) -> CliResult<(Hash, Option<u64>)> { |
| 238 | // Search for matching changes |
| 239 | let mut matches: Vec<Hash> = Vec::new(); |
| 240 | |
| 241 | for result in repo.iter_changes() { |
| 242 | let hash = result.map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?; |
| 243 | let hash_str = hash.to_base32(); |
| 244 | if hash_str.starts_with(prefix) { |
| 245 | matches.push(hash); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | match matches.len() { |
| 250 | 0 => Err(CliError::ChangeNotFound { |
| 251 | hash: prefix.to_string(), |
| 252 | }), |
| 253 | 1 => { |
| 254 | let hash = matches[0]; |
| 255 | let seq = self.find_sequence_for_hash(repo, view_name, &hash)?; |
| 256 | Ok((hash, seq)) |
| 257 | } |
| 258 | _ => { |
| 259 | // Format the matches for display in the error message |
| 260 | let match_list: Vec<String> = matches.iter().map(|h| h.to_base32()).collect(); |
| 261 | Err(CliError::AmbiguousHash { |
| 262 | hash: format!("{} (matches: {})", prefix, match_list.join(", ")), |
| 263 | }) |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /// Resolve a sequence number to a hash. |
| 269 | fn resolve_sequence(&self, repo: &Repository, view_name: &str, seq: u64) -> CliResult<Hash> { |
no test coverage detected