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

Method save_provenance_graph

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

Save a provenance graph to the repository. Serializes the graph to disk, registers it in the pristine database with `node_type::PROVENANCE`, and records dependencies on the changes this graph explains. # Returns The content hash of the saved provenance graph.

(
        &self,
        graph: &atomic_core::change::ProvenanceGraph,
    )

Source from the content-addressed store, hash-verified

634 ///
635 /// The content hash of the saved provenance graph.
636 pub fn save_provenance_graph(
637 &self,
638 graph: &atomic_core::change::ProvenanceGraph,
639 ) -> Result<Hash, RepositoryError> {
640 use atomic_core::pristine::MutTxnT;
641
642 // Save to disk
643 let hash = self
644 .change_store
645 .save_provenance_graph(graph)
646 .map_err(|e| RepositoryError::Database(e.to_string()))?;
647
648 // Register in the graph
649 let mut txn = self
650 .pristine
651 .write_txn()
652 .map_err(|e| RepositoryError::Database(e.to_string()))?;
653
654 let prov_id = txn
655 .register_provenance(&hash)
656 .map_err(|e| RepositoryError::Database(e.to_string()))?;
657
658 // Register dependencies: provenance → explained changes
659 for change_hash in &graph.changes_explained {
660 if let Ok(Some(change_id)) = txn.get_internal(change_hash) {
661 txn.put_dep(prov_id, change_id)
662 .map_err(|e| RepositoryError::Database(e.to_string()))?;
663 }
664 }
665
666 // If chained, register dependency on previous provenance graph too
667 if let Some(ref prev_hash) = graph.previous {
668 if let Ok(Some(prev_id)) = txn.get_internal(prev_hash) {
669 txn.put_dep(prov_id, prev_id)
670 .map_err(|e| RepositoryError::Database(e.to_string()))?;
671 }
672 }
673
674 // Populate session tables if this is a Sherpa provenance graph.
675 // The write transaction is still open, so this is atomic with
676 // the provenance registration above.
677 txn.populate_session_tables(prov_id.get(), graph)
678 .map_err(|e| RepositoryError::Database(e.to_string()))?;
679
680 txn.commit()
681 .map_err(|e| RepositoryError::Database(e.to_string()))?;
682
683 Ok(hash)
684 }
685
686 /// Load a provenance graph from the repository by hash.
687 pub fn load_provenance_graph(

Callers 1

save_turn_provenanceMethod · 0.45

Calls 7

write_txnMethod · 0.80
register_provenanceMethod · 0.80
put_depMethod · 0.80
commitMethod · 0.80
getMethod · 0.65
get_internalMethod · 0.45

Tested by

no test coverage detected