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,
)
| 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( |
no test coverage detected