Find a change by hash prefix.
(
&self,
repo: &Repository,
workspace_view: &str,
hash_str: &str,
)
| 331 | |
| 332 | /// Find a change by hash prefix. |
| 333 | fn find_by_hash( |
| 334 | &self, |
| 335 | repo: &Repository, |
| 336 | workspace_view: &str, |
| 337 | hash_str: &str, |
| 338 | ) -> CliResult<u64> { |
| 339 | // Get history and search for matching hash |
| 340 | let history = repo |
| 341 | .log(HistoryOptions::default().view(workspace_view)) |
| 342 | .map_err(CliError::Repository)?; |
| 343 | |
| 344 | let hash_lower = hash_str.to_lowercase(); |
| 345 | let mut found: Option<u64> = None; |
| 346 | |
| 347 | for entry in history { |
| 348 | let entry_hash = entry.hash.to_base32().to_lowercase(); |
| 349 | if entry_hash.starts_with(&hash_lower) { |
| 350 | if found.is_some() { |
| 351 | return Err(CliError::AmbiguousHash { |
| 352 | hash: hash_str.to_string(), |
| 353 | }); |
| 354 | } |
| 355 | found = Some(entry.sequence); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | found.ok_or_else(|| CliError::ChangeNotFound { |
| 360 | hash: hash_str.to_string(), |
| 361 | }) |
| 362 | } |
| 363 | |
| 364 | /// Get the message for the revised change. |
| 365 | /// |
no test coverage detected