Resolve a change reference (full hash or prefix) to a full hash.
(
&self,
repo: &Repository,
change_ref: &str,
)
| 895 | |
| 896 | /// Resolve a change reference (full hash or prefix) to a full hash. |
| 897 | pub(super) fn resolve_change_ref( |
| 898 | &self, |
| 899 | repo: &Repository, |
| 900 | change_ref: &str, |
| 901 | ) -> CliResult<Hash> { |
| 902 | // Try to parse as a full hash first |
| 903 | if let Some(hash) = Hash::from_base32(change_ref.as_bytes()) { |
| 904 | if repo.has_change(&hash) { |
| 905 | return Ok(hash); |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | // Search for matching changes by prefix |
| 910 | let mut matches: Vec<Hash> = Vec::new(); |
| 911 | let prefix_upper = change_ref.to_uppercase(); |
| 912 | |
| 913 | for result in repo.iter_changes() { |
| 914 | let hash = result.map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?; |
| 915 | let hash_str = hash.to_base32(); |
| 916 | if hash_str.starts_with(&prefix_upper) { |
| 917 | matches.push(hash); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | match matches.len() { |
| 922 | 0 => Err(CliError::ChangeNotFound { |
| 923 | hash: change_ref.to_string(), |
| 924 | }), |
| 925 | 1 => Ok(matches[0]), |
| 926 | _ => { |
| 927 | let match_list: Vec<String> = matches.iter().map(|h| h.to_base32()).collect(); |
| 928 | Err(CliError::AmbiguousHash { |
| 929 | hash: format!("{} (matches: {})", change_ref, match_list.join(", ")), |
| 930 | }) |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | /// Build the real per-file unified diff for a recorded change WITHOUT printing. |
no test coverage detected