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,
)
| 1321 | /// disk-scan fallback when REV_DEPS registration missed the change. |
| 1322 | /// Errors if no graph explains the change. |
| 1323 | pub(crate) fn load_graphs( |
| 1324 | repo: &Repository, |
| 1325 | change_hash: &Hash, |
| 1326 | ) -> Result<Vec<(Hash, ProvenanceGraph)>, RepositoryError> { |
| 1327 | let mut graphs = repo.find_provenance_for_change(change_hash)?; |
| 1328 | if graphs.is_empty() { |
| 1329 | graphs = repo.find_provenance_for_change_scan(change_hash)?; |
| 1330 | } |
| 1331 | if graphs.is_empty() { |
| 1332 | return Err(RepositoryError::InvalidOperation { |
| 1333 | message: format!( |
| 1334 | "no provenance graph explains change {}", |
| 1335 | change_hash.to_base32() |
| 1336 | ), |
| 1337 | }); |
| 1338 | } |
| 1339 | // Most-recent first (a change explained by >1 graph shows all; the newest |
| 1340 | // leads). Both loaders sort/return unspecified order, so sort here. |
| 1341 | graphs.sort_by_key(|(_, g)| { |
| 1342 | std::cmp::Reverse(atomic_core::types::timestamp::epoch_millis(g.timestamp)) |
| 1343 | }); |
| 1344 | Ok(graphs) |
| 1345 | } |
| 1346 | |
| 1347 | #[cfg(test)] |
| 1348 | mod tests { |
no test coverage detected