Insert a change with automatic dependency resolution. This method attempts to insert a change and all its missing dependencies. Dependencies are inserted in topological order (dependencies before dependents). # Arguments `hash` - The hash of the change to insert `options` - Options controlling insertion behavior # Returns An `InsertOutcome` containing aggregate statistics for all inserted cha
(
&self,
hash: &Hash,
mut options: InsertOptions,
)
| 2884 | /// println!("Inserted {} changes", result.stats.changes_applied); |
| 2885 | /// ``` |
| 2886 | pub fn insert_change_rec( |
| 2887 | &self, |
| 2888 | hash: &Hash, |
| 2889 | mut options: InsertOptions, |
| 2890 | ) -> Result<InsertOutcome, RepositoryError> { |
| 2891 | let _review_boundary = self.review_evidence_lock()?; |
| 2892 | self.fence_legacy_span_storage(&self.load_change(hash)?)?; |
| 2893 | #[cfg(feature = "prototype-context-completion")] |
| 2894 | if !self |
| 2895 | .prototype_projection_for_hashes(&[*hash])? |
| 2896 | .effects |
| 2897 | .is_empty() |
| 2898 | { |
| 2899 | return Err(RepositoryError::InvalidOperation { |
| 2900 | message: "experimental context closure requires prototype_insert_composed before any membership mutation".into(), |
| 2901 | }); |
| 2902 | } |
| 2903 | let _span_lock = if self.span_in_closure(std::slice::from_ref(hash))? { |
| 2904 | let lock = self.try_lock_workspace_operation(self.require_working_copy_id()?)?; |
| 2905 | self.preflight_span_references( |
| 2906 | options.view.as_deref().unwrap_or(&self.current_view), |
| 2907 | std::slice::from_ref(hash), |
| 2908 | false, |
| 2909 | )?; |
| 2910 | Some(lock) |
| 2911 | } else { |
| 2912 | None |
| 2913 | }; |
| 2914 | let trace_insert = std::env::var_os("ATOMIC_TRACE_INSERT").is_some(); |
| 2915 | let t0 = std::time::Instant::now(); |
| 2916 | |
| 2917 | // Load the target change to get its dependencies. |
| 2918 | let _change = self.load_change(hash)?; |
| 2919 | |
| 2920 | // Get the view name |
| 2921 | let view_name = options.view.as_deref().unwrap_or(&self.current_view); |
| 2922 | |
| 2923 | if trace_insert { |
| 2924 | eprintln!( |
| 2925 | "[insert_change_rec] start hash={} view={}", |
| 2926 | &hash.to_base32()[..12], |
| 2927 | view_name, |
| 2928 | ); |
| 2929 | } |
| 2930 | |
| 2931 | // Get a read transaction to check what's already inserted |
| 2932 | let read_txn = self |
| 2933 | .pristine |
| 2934 | .read_txn() |
| 2935 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 2936 | |
| 2937 | let view = read_txn |
| 2938 | .get_view(view_name) |
| 2939 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 2940 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 2941 | name: view_name.to_string(), |
| 2942 | })?; |
| 2943 |