Find a change by hash prefix. This searches through all stored changes to find one whose hash starts with the given prefix. Useful for CLI commands that allow abbreviated hashes. # Arguments `prefix` - The hash prefix (case-insensitive, at least 2 characters) # Returns `Ok(Some(hash))` - Found a unique matching change `Ok(None)` - No change matched the prefix `Err(_)` - Multiple changes match
(&self, prefix: &str)
| 1019 | /// } |
| 1020 | /// ``` |
| 1021 | pub fn find_change_by_prefix(&self, prefix: &str) -> Result<Option<Hash>, RepositoryError> { |
| 1022 | let prefix_upper = prefix.to_uppercase(); |
| 1023 | let mut matches = Vec::new(); |
| 1024 | |
| 1025 | for result in self.iter_changes() { |
| 1026 | let hash = result?; |
| 1027 | let hash_str = hash.to_base32(); |
| 1028 | if hash_str.starts_with(&prefix_upper) { |
| 1029 | matches.push(hash); |
| 1030 | // If we find more than one, it's ambiguous |
| 1031 | if matches.len() > 1 { |
| 1032 | return Err(RepositoryError::AmbiguousHash { |
| 1033 | prefix: prefix.to_string(), |
| 1034 | matches: matches.iter().map(|h| h.to_base32()).collect(), |
| 1035 | }); |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | Ok(matches.into_iter().next()) |
| 1041 | } |
| 1042 | |
| 1043 | // ========================================================================= |
| 1044 | // Provenance Graph Operations |