Resolve a change reference (full hash or prefix) to a full hash.
(
&self,
repo: &Repository,
change_ref: &str,
)
| 833 | |
| 834 | /// Resolve a change reference (full hash or prefix) to a full hash. |
| 835 | pub(super) fn resolve_change_ref( |
| 836 | &self, |
| 837 | repo: &Repository, |
| 838 | change_ref: &str, |
| 839 | ) -> CliResult<Hash> { |
| 840 | // Try to parse as a full hash first |
| 841 | if let Some(hash) = Hash::from_base32(change_ref.as_bytes()) { |
| 842 | if repo.has_change(&hash) { |
| 843 | return Ok(hash); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | // Search for matching changes by prefix |
| 848 | let mut matches: Vec<Hash> = Vec::new(); |
| 849 | let prefix_upper = change_ref.to_uppercase(); |
| 850 | |
| 851 | for result in repo.iter_changes() { |
| 852 | let hash = result.map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?; |
| 853 | let hash_str = hash.to_base32(); |
| 854 | if hash_str.starts_with(&prefix_upper) { |
| 855 | matches.push(hash); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | match matches.len() { |
| 860 | 0 => Err(CliError::ChangeNotFound { |
| 861 | hash: change_ref.to_string(), |
| 862 | }), |
| 863 | 1 => Ok(matches[0]), |
| 864 | _ => { |
| 865 | let match_list: Vec<String> = matches.iter().map(|h| h.to_base32()).collect(); |
| 866 | Err(CliError::AmbiguousHash { |
| 867 | hash: format!("{} (matches: {})", change_ref, match_list.join(", ")), |
| 868 | }) |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | /// Build the real per-file unified diff for a recorded change WITHOUT printing. |
no test coverage detected