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

Function load_graphs

atomic-cli/src/commands/provenance/command.rs:148–172  ·  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

146/// fallback when REV_DEPS registration missed the change. Errors if no graph
147/// explains the change.
148pub(crate) fn load_graphs(
149 repo: &Repository,
150 change_hash: &Hash,
151) -> CliResult<Vec<(Hash, ProvenanceGraph)>> {
152 let mut graphs = repo
153 .find_provenance_for_change(change_hash)
154 .map_err(CliError::Repository)?;
155 if graphs.is_empty() {
156 graphs = repo
157 .find_provenance_for_change_scan(change_hash)
158 .map_err(CliError::Repository)?;
159 }
160 if graphs.is_empty() {
161 return Err(CliError::InvalidArgument {
162 message: format!(
163 "no provenance graph explains change {}",
164 change_hash.to_base32()
165 ),
166 });
167 }
168 // Most-recent first (a change explained by >1 graph shows all; the newest
169 // leads). Both loaders sort/return unspecified order, so sort here.
170 graphs.sort_by_key(|(_, g)| std::cmp::Reverse(g.timestamp));
171 Ok(graphs)
172}
173
174/// Resolve the CLI target (bare hash, hash prefix, or `urn:atomic:change:<b32>`)
175/// to a change `Hash`.

Callers 2

runMethod · 0.85
load_provenance_compactFunction · 0.85

Calls 3

is_emptyMethod · 0.45

Tested by

no test coverage detected