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

Method resolve_change_ref

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

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

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