MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / resolve_change_ref

Method resolve_change_ref

atomic-cli/src/commands/diff/helpers.rs:897–933  ·  view source on GitHub ↗

Resolve a change reference (full hash or prefix) to a full hash.

(
        &self,
        repo: &Repository,
        change_ref: &str,
    )

Source from the content-addressed store, hash-verified

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.

Callers 1

show_change_diffMethod · 0.80

Calls 8

as_bytesMethod · 0.45
has_changeMethod · 0.45
iter_changesMethod · 0.45
to_base32Method · 0.45
pushMethod · 0.45
lenMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected