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)
| 4916 | /// Log entries, newest first, the same resolution the in-process |
| 4917 | /// `resolve_change` performs. |
| 4918 | fn 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) |