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

Method find_by_prefix

atomic-cli/src/commands/agent/attest.rs:578–616  ·  view source on GitHub ↗

Find an attestation by hash or hash prefix.

(&self, repo: &Repository, prefix: &str)

Source from the content-addressed store, hash-verified

576
577 /// Find an attestation by hash or hash prefix.
578 fn find_by_prefix(&self, repo: &Repository, prefix: &str) -> CliResult<(Hash, Attestation)> {
579 // Try exact match first
580 if let Some(hash) = Hash::from_base32(prefix.as_bytes()) {
581 if let Ok(attest) = repo.load_attestation(&hash) {
582 return Ok((hash, attest));
583 }
584 }
585
586 // Prefix search
587 let prefix_lower = prefix.to_uppercase();
588 let mut matches: Vec<(Hash, Attestation)> = Vec::new();
589
590 for result in repo.change_store().iter_attestations() {
591 let hash = match result {
592 Ok(h) => h,
593 Err(_) => continue,
594 };
595
596 let hash_str = hash.to_base32();
597 if hash_str.starts_with(&prefix_lower) {
598 if let Ok(attest) = repo.load_attestation(&hash) {
599 matches.push((hash, attest));
600 }
601 }
602 }
603
604 match matches.len() {
605 0 => Err(CliError::InvalidArgument {
606 message: format!("No attestation found matching '{}'", prefix),
607 }),
608 1 => Ok(matches.into_iter().next().unwrap()),
609 n => Err(CliError::InvalidArgument {
610 message: format!(
611 "Ambiguous hash prefix '{}' matches {} attestations. Be more specific.",
612 prefix, n,
613 ),
614 }),
615 }
616 }
617
618 /// Print a one-line summary of an attestation.
619 fn print_summary(&self, hash: &Hash, attest: &Attestation) {

Callers 1

show_detailMethod · 0.80

Calls 10

iter_attestationsMethod · 0.80
as_bytesMethod · 0.45
load_attestationMethod · 0.45
change_storeMethod · 0.45
to_base32Method · 0.45
pushMethod · 0.45
lenMethod · 0.45
unwrapMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected