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

Function resolve_provenance_target

libatomic/src/daemon/services_agent.rs:5352–5391  ·  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

5350/// The raw CLI target (bare hash, hash prefix, or URN) → the change hash —
5351/// the provenance command's resolver semantics verbatim.
5352fn resolve_provenance_target(
5353 repo: &atomic_repository::Repository,
5354 target: &str,
5355) -> Result<atomic_core::types::Merkle, Status> {
5356 use atomic_core::types::Base32;
5357 const URN_PREFIX: &str = "urn:atomic:change:";
5358 if let Some(base32) = target.strip_prefix(URN_PREFIX) {
5359 return atomic_core::types::Hash::from_base32(base32.as_bytes()).ok_or_else(|| {
5360 domain_status(
5361 ErrorCode::InvalidArgument,
5362 format!("invalid change base32 in URN: {target}"),
5363 )
5364 });
5365 }
5366 let mut matches = Vec::new();
5367 for result in repo.iter_changes() {
5368 let hash =
5369 result.map_err(|error| domain_status(ErrorCode::Repository, error.to_string()))?;
5370 if hash.to_base32().starts_with(target) {
5371 matches.push(hash);
5372 }
5373 }
5374 match matches.len() {
5375 0 => atomic_core::types::Hash::from_base32(target.as_bytes()).ok_or_else(|| {
5376 domain_status(ErrorCode::NotFound, format!("change not found: {target}"))
5377 }),
5378 1 => Ok(matches[0]),
5379 _ => {
5380 let list: Vec<String> = matches.iter().map(|hash| hash.to_base32()).collect();
5381 Err(domain_status(
5382 ErrorCode::InvalidArgument,
5383 format!(
5384 "ambiguous change prefix {} (matches: {})",
5385 target,
5386 list.join(", ")
5387 ),
5388 ))
5389 }
5390 }
5391}

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