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

Function resolve_change_hash

atomic-cli/src/commands/rpc.rs:4958–5007  ·  view source on GitHub ↗

Resolve a hash prefix to the full hash through the service layer — Log entries, newest first, the same resolution the in-process `resolve_change` performs.

(session: &Service, prefix: &str)

Source from the content-addressed store, hash-verified

4956/// Log entries, newest first, the same resolution the in-process
4957/// `resolve_change` performs.
4958fn resolve_change_hash(session: &Service, prefix: &str) -> CliResult<Merkle> {
4959 let request = pb::LogRequest {
4960 repository: Some(session.reference.clone()),
4961 all_views: false,
4962 view: None,
4963 cursor: None,
4964 budget: Some(pb::PageBudget {
4965 max_items: Some(200),
4966 max_bytes: None,
4967 }),
4968 path_filter: Vec::new(),
4969 tags_only: false,
4970 };
4971 let entries = session.log(request)?.entries;
4972 let matches: Vec<_> = entries
4973 .iter()
4974 .filter(|entry| {
4975 entry
4976 .hash
4977 .as_ref()
4978 .map(|h| {
4979 h.value
4980 .clone()
4981 .try_into()
4982 .map(|bytes: [u8; 32]| Merkle(bytes).to_base32().starts_with(prefix))
4983 .unwrap_or(false)
4984 })
4985 .unwrap_or(false)
4986 })
4987 .collect();
4988 match matches.len() {
4989 0 => Err(CliError::InvalidArgument {
4990 message: format!("No change found matching '{prefix}'"),
4991 }),
4992 1 => {
4993 let bytes: [u8; 32] = matches[0]
4994 .hash
4995 .as_ref()
4996 .expect("matched entry has a hash")
4997 .value
4998 .clone()
4999 .try_into()
5000 .map_err(|_| CliError::Internal(anyhow::anyhow!("malformed hash")))?;
5001 Ok(Merkle(bytes))
5002 }
5003 _ => Err(CliError::InvalidArgument {
5004 message: format!("Ambiguous change prefix '{prefix}'"),
5005 }),
5006 }
5007}
5008
5009// ---------------------------------------------------------------------------
5010// provenance trace/show (ProvenanceService.ExportProvenance)

Callers 1

query_enrichFunction · 0.85

Calls 8

MerkleClass · 0.85
as_refMethod · 0.80
cloneMethod · 0.45
logMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
to_base32Method · 0.45
lenMethod · 0.45

Tested by

no test coverage detected