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

Method resolve_change_ref

atomic-cli/src/commands/diff/helpers.rs:738–774  ·  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

736
737 /// Resolve a change reference (full hash or prefix) to a full hash.
738 pub(super) fn resolve_change_ref(
739 &self,
740 repo: &Repository,
741 change_ref: &str,
742 ) -> CliResult<Hash> {
743 // Try to parse as a full hash first
744 if let Some(hash) = Hash::from_base32(change_ref.as_bytes()) {
745 if repo.has_change(&hash) {
746 return Ok(hash);
747 }
748 }
749
750 // Search for matching changes by prefix
751 let mut matches: Vec<Hash> = Vec::new();
752 let prefix_upper = change_ref.to_uppercase();
753
754 for result in repo.iter_changes() {
755 let hash = result.map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?;
756 let hash_str = hash.to_base32();
757 if hash_str.starts_with(&prefix_upper) {
758 matches.push(hash);
759 }
760 }
761
762 match matches.len() {
763 0 => Err(CliError::ChangeNotFound {
764 hash: change_ref.to_string(),
765 }),
766 1 => Ok(matches[0]),
767 _ => {
768 let match_list: Vec<String> = matches.iter().map(|h| h.to_base32()).collect();
769 Err(CliError::AmbiguousHash {
770 hash: format!("{} (matches: {})", change_ref, match_list.join(", ")),
771 })
772 }
773 }
774 }
775}

Callers 1

show_change_diffMethod · 0.80

Calls 7

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

Tested by

no test coverage detected