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

Function resolve_provenance_target

libatomic/src/daemon/services_agent.rs:5404–5443  ·  view source on GitHub ↗

The raw CLI target (bare hash, hash prefix, or URN) → the change hash — the provenance command's resolver semantics verbatim.

(
    repo: &atomic_repository::Repository,
    target: &str,
)

Source from the content-addressed store, hash-verified

5402/// The raw CLI target (bare hash, hash prefix, or URN) → the change hash —
5403/// the provenance command's resolver semantics verbatim.
5404fn resolve_provenance_target(
5405 repo: &atomic_repository::Repository,
5406 target: &str,
5407) -> Result<atomic_core::types::Merkle, Status> {
5408 use atomic_core::types::Base32;
5409 const URN_PREFIX: &str = "urn:atomic:change:";
5410 if let Some(base32) = target.strip_prefix(URN_PREFIX) {
5411 return atomic_core::types::Hash::from_base32(base32.as_bytes()).ok_or_else(|| {
5412 domain_status(
5413 ErrorCode::InvalidArgument,
5414 format!("invalid change base32 in URN: {target}"),
5415 )
5416 });
5417 }
5418 let mut matches = Vec::new();
5419 for result in repo.iter_changes() {
5420 let hash =
5421 result.map_err(|error| domain_status(ErrorCode::Repository, error.to_string()))?;
5422 if hash.to_base32().starts_with(target) {
5423 matches.push(hash);
5424 }
5425 }
5426 match matches.len() {
5427 0 => atomic_core::types::Hash::from_base32(target.as_bytes()).ok_or_else(|| {
5428 domain_status(ErrorCode::NotFound, format!("change not found: {target}"))
5429 }),
5430 1 => Ok(matches[0]),
5431 _ => {
5432 let list: Vec<String> = matches.iter().map(|hash| hash.to_base32()).collect();
5433 Err(domain_status(
5434 ErrorCode::InvalidArgument,
5435 format!(
5436 "ambiguous change prefix {} (matches: {})",
5437 target,
5438 list.join(", ")
5439 ),
5440 ))
5441 }
5442 }
5443}

Callers 1

export_provenance_implFunction · 0.85

Calls 8

domain_statusFunction · 0.85
as_bytesMethod · 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