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