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

Function export_provenance_impl

libatomic/src/daemon/services_agent.rs:5241–5348  ·  view source on GitHub ↗

The ExportProvenance domain: resolve the target (URN/prefix/hash with the CLI resolver's exact semantics), load the explaining graphs (the REV_DEPS lookup with the disk-scan fallback, newest first), map each to the projection input, and pre-walk the prior-turn chain the human trace renders. The CLI projects/signs client-side over the bundles.

(
    state: std::sync::Arc<DaemonState>,
    request: Request<ExportProvenanceRequest>,
)

Source from the content-addressed store, hash-verified

5239/// to the projection input, and pre-walk the prior-turn chain the human
5240/// trace renders. The CLI projects/signs client-side over the bundles.
5241async fn export_provenance_impl(
5242 state: std::sync::Arc<DaemonState>,
5243 request: Request<ExportProvenanceRequest>,
5244) -> Result<Response<ExportProvenanceResponse>, Status> {
5245 use atomic_core::types::Base32;
5246 let request = request.into_inner();
5247 let handle = state.resolve(request.repository.as_ref().unwrap())?;
5248 state.log_rpc("ExportProvenance", Some(&handle));
5249 let gate_handle = handle.clone();
5250 let _gate = gate_handle.exclusive().await;
5251 let target = request.target.clone();
5252 let exact = request.change.as_ref().and_then(|hash| {
5253 hash.value
5254 .clone()
5255 .try_into()
5256 .ok()
5257 .map(atomic_core::types::Merkle)
5258 });
5259 let person_did = request.person_did.clone().unwrap_or_default();
5260 let (resolved, bundles) = tokio::task::spawn_blocking(move || {
5261 let repo = handle.repository_readonly()?;
5262 // Resolve the target: the raw CLI string (URN / prefix / full
5263 // base32), else the request's exact hash.
5264 let change_hash = match &target {
5265 Some(target) => resolve_provenance_target(&repo, target)?,
5266 None => exact.ok_or_else(|| {
5267 domain_status(ErrorCode::InvalidArgument, "change target required")
5268 })?,
5269 };
5270 // The graphs that explain the change, newest first (the CLI's
5271 // load_graphs: REV_DEPS first, disk-scan fallback, error when
5272 // nothing explains it).
5273 let mut graphs = repo
5274 .find_provenance_for_change(&change_hash)
5275 .map_err(repository_error)?;
5276 if graphs.is_empty() {
5277 graphs = repo
5278 .find_provenance_for_change_scan(&change_hash)
5279 .map_err(repository_error)?;
5280 }
5281 if graphs.is_empty() {
5282 return Err(domain_status(
5283 ErrorCode::InvalidArgument,
5284 format!(
5285 "no provenance graph explains change {}",
5286 change_hash.to_base32()
5287 ),
5288 ));
5289 }
5290 graphs.sort_by_key(|(_, graph)| {
5291 std::cmp::Reverse(atomic_core::types::timestamp::epoch_millis(graph.timestamp))
5292 });
5293 let mut bundles = Vec::with_capacity(graphs.len());
5294 for (graph_hash, graph) in &graphs {
5295 let (input, previous) = provenance_map_input(&repo, graph, &change_hash, &person_did);
5296 // The prior-turn walk the trace render performs (≤64 hops; an
5297 // unloadable graph ends the chain with the empty marker, the
5298 // cap sets the truncated flag — the local render's two

Callers 1

export_provenanceMethod · 0.85

Calls 15

domain_statusFunction · 0.85
epoch_millisFunction · 0.85
provenance_map_inputFunction · 0.85
activity_urnFunction · 0.85
provenance_activity_idFunction · 0.85
prov_input_bundleFunction · 0.85
as_refMethod · 0.80
log_rpcMethod · 0.80
exclusiveMethod · 0.80
repository_readonlyMethod · 0.80

Tested by

no test coverage detected