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