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

Method find_provenance_for_change

atomic-repository/src/repository/changes.rs:1141–1195  ·  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

1139 ///
1140 /// A vector of `(Hash, ProvenanceGraph)` pairs explaining this change.
1141 pub fn find_provenance_for_change(
1142 &self,
1143 change_hash: &Hash,
1144 ) -> Result<Vec<(Hash, atomic_core::change::ProvenanceGraph)>, RepositoryError> {
1145 use atomic_core::pristine::{node_type, GraphTxnT};
1146
1147 let txn = self
1148 .pristine
1149 .read_txn()
1150 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1151
1152 // Get the internal ID for this change
1153 let change_id = match txn
1154 .get_internal(change_hash)
1155 .map_err(|e| RepositoryError::Database(e.to_string()))?
1156 {
1157 Some(id) => id,
1158 None => return Ok(Vec::new()),
1159 };
1160
1161 // Look up REV_DEPS: who depends on this change?
1162 let rev_deps = txn
1163 .get_rev_deps(change_id)
1164 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1165
1166 let mut graphs = Vec::new();
1167
1168 for dep_id in rev_deps {
1169 // Check if this dependent is a provenance graph
1170 let node_type_val = txn
1171 .get_node_type(dep_id)
1172 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1173
1174 if node_type_val != Some(node_type::PROVENANCE) {
1175 continue;
1176 }
1177
1178 // Get the external hash
1179 let dep_hash = match txn
1180 .get_external(dep_id)
1181 .map_err(|e| RepositoryError::Database(e.to_string()))?
1182 {
1183 Some(h) => h,
1184 None => continue,
1185 };
1186
1187 // Load the provenance graph from disk
1188 match self.load_provenance_graph(&dep_hash) {
1189 Ok(graph) => graphs.push((dep_hash, graph)),
1190 Err(_) => continue, // File missing or corrupt — skip
1191 }
1192 }
1193
1194 Ok(graphs)
1195 }
1196
1197 /// Find all provenance graphs that explain a change by scanning disk.
1198 ///

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