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

Function resolve_change_hash

atomic-cli/src/commands/rpc.rs:4918–4967  ·  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

4916/// Log entries, newest first, the same resolution the in-process
4917/// `resolve_change` performs.
4918fn resolve_change_hash(session: &Service, prefix: &str) -> CliResult<Merkle> {
4919 let request = pb::LogRequest {
4920 repository: Some(session.reference.clone()),
4921 all_views: false,
4922 view: None,
4923 cursor: None,
4924 budget: Some(pb::PageBudget {
4925 max_items: Some(200),
4926 max_bytes: None,
4927 }),
4928 path_filter: Vec::new(),
4929 tags_only: false,
4930 };
4931 let entries = session.log(request)?.entries;
4932 let matches: Vec<_> = entries
4933 .iter()
4934 .filter(|entry| {
4935 entry
4936 .hash
4937 .as_ref()
4938 .map(|h| {
4939 h.value
4940 .clone()
4941 .try_into()
4942 .map(|bytes: [u8; 32]| Merkle(bytes).to_base32().starts_with(prefix))
4943 .unwrap_or(false)
4944 })
4945 .unwrap_or(false)
4946 })
4947 .collect();
4948 match matches.len() {
4949 0 => Err(CliError::InvalidArgument {
4950 message: format!("No change found matching '{prefix}'"),
4951 }),
4952 1 => {
4953 let bytes: [u8; 32] = matches[0]
4954 .hash
4955 .as_ref()
4956 .expect("matched entry has a hash")
4957 .value
4958 .clone()
4959 .try_into()
4960 .map_err(|_| CliError::Internal(anyhow::anyhow!("malformed hash")))?;
4961 Ok(Merkle(bytes))
4962 }
4963 _ => Err(CliError::InvalidArgument {
4964 message: format!("Ambiguous change prefix '{prefix}'"),
4965 }),
4966 }
4967}
4968
4969// ---------------------------------------------------------------------------
4970// 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