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,
)
| 5350 | /// The raw CLI target (bare hash, hash prefix, or URN) → the change hash — |
| 5351 | /// the provenance command's resolver semantics verbatim. |
| 5352 | fn 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 | } |
no test coverage detected