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

Function load_graphs

atomic-cli/src/commands/provenance/command.rs:224–250  ·  view source on GitHub ↗

Load a change's provenance graphs: REV_DEPS-backed lookup, with a disk-scan fallback when REV_DEPS registration missed the change. Errors if no graph explains the change.

(
    repo: &Repository,
    change_hash: &Hash,
)

Source from the content-addressed store, hash-verified

222/// fallback when REV_DEPS registration missed the change. Errors if no graph
223/// explains the change.
224pub(crate) fn load_graphs(
225 repo: &Repository,
226 change_hash: &Hash,
227) -> CliResult<Vec<(Hash, ProvenanceGraph)>> {
228 let mut graphs = repo
229 .find_provenance_for_change(change_hash)
230 .map_err(CliError::Repository)?;
231 if graphs.is_empty() {
232 graphs = repo
233 .find_provenance_for_change_scan(change_hash)
234 .map_err(CliError::Repository)?;
235 }
236 if graphs.is_empty() {
237 return Err(CliError::InvalidArgument {
238 message: format!(
239 "no provenance graph explains change {}",
240 change_hash.to_base32()
241 ),
242 });
243 }
244 // Most-recent first (a change explained by >1 graph shows all; the newest
245 // leads). Both loaders sort/return unspecified order, so sort here.
246 graphs.sort_by_key(|(_, g)| {
247 std::cmp::Reverse(atomic_core::types::timestamp::epoch_millis(g.timestamp))
248 });
249 Ok(graphs)
250}
251
252/// Resolve the CLI target (bare hash, hash prefix, or `urn:atomic:change:<b32>`)
253/// to a change `Hash`.

Callers 1

runMethod · 0.70

Calls 4

epoch_millisFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected