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

Method find_provenance_for_change

atomic-repository/src/repository/changes.rs:713–767  ·  view source on GitHub ↗

Find all provenance graphs that explain a specific change. Uses REV_DEPS to find nodes that depend on the given change, then filters by `node_type::PROVENANCE`. # Arguments `change_hash` - The hash of the change to find provenance for # Returns A vector of `(Hash, ProvenanceGraph)` pairs explaining this change.

(
        &self,
        change_hash: &Hash,
    )

Source from the content-addressed store, hash-verified

711 ///
712 /// A vector of `(Hash, ProvenanceGraph)` pairs explaining this change.
713 pub fn find_provenance_for_change(
714 &self,
715 change_hash: &Hash,
716 ) -> Result<Vec<(Hash, atomic_core::change::ProvenanceGraph)>, RepositoryError> {
717 use atomic_core::pristine::{node_type, GraphTxnT};
718
719 let txn = self
720 .pristine
721 .read_txn()
722 .map_err(|e| RepositoryError::Database(e.to_string()))?;
723
724 // Get the internal ID for this change
725 let change_id = match txn
726 .get_internal(change_hash)
727 .map_err(|e| RepositoryError::Database(e.to_string()))?
728 {
729 Some(id) => id,
730 None => return Ok(Vec::new()),
731 };
732
733 // Look up REV_DEPS: who depends on this change?
734 let rev_deps = txn
735 .get_rev_deps(change_id)
736 .map_err(|e| RepositoryError::Database(e.to_string()))?;
737
738 let mut graphs = Vec::new();
739
740 for dep_id in rev_deps {
741 // Check if this dependent is a provenance graph
742 let node_type_val = txn
743 .get_node_type(dep_id)
744 .map_err(|e| RepositoryError::Database(e.to_string()))?;
745
746 if node_type_val != Some(node_type::PROVENANCE) {
747 continue;
748 }
749
750 // Get the external hash
751 let dep_hash = match txn
752 .get_external(dep_id)
753 .map_err(|e| RepositoryError::Database(e.to_string()))?
754 {
755 Some(h) => h,
756 None => continue,
757 };
758
759 // Load the provenance graph from disk
760 match self.load_provenance_graph(&dep_hash) {
761 Ok(graph) => graphs.push((dep_hash, graph)),
762 Err(_) => continue, // File missing or corrupt — skip
763 }
764 }
765
766 Ok(graphs)
767 }
768
769 /// Find all provenance graphs that explain a change by scanning disk.
770 ///

Calls 7

read_txnMethod · 0.80
get_internalMethod · 0.45
get_rev_depsMethod · 0.45
get_node_typeMethod · 0.45
get_externalMethod · 0.45
load_provenance_graphMethod · 0.45
pushMethod · 0.45