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,
)
| 2854 | /// println!("Inserted {} changes", result.stats.changes_applied); |
| 2855 | /// ``` |
| 2856 | pub fn insert_change_rec( |
| 2857 | &self, |
| 2858 | hash: &Hash, |
| 2859 | mut options: InsertOptions, |
| 2860 | ) -> Result<InsertOutcome, RepositoryError> { |
| 2861 | let _span_lock = if self.span_in_closure(std::slice::from_ref(hash))? { |
| 2862 | let lock = self.try_lock_workspace_operation(self.require_working_copy_id()?)?; |
| 2863 | self.preflight_span_references( |
| 2864 | options.view.as_deref().unwrap_or(&self.current_view), |
| 2865 | std::slice::from_ref(hash), |
| 2866 | false, |
| 2867 | )?; |
| 2868 | Some(lock) |
| 2869 | } else { |
| 2870 | None |
| 2871 | }; |
| 2872 | let trace_insert = std::env::var_os("ATOMIC_TRACE_INSERT").is_some(); |
| 2873 | let t0 = std::time::Instant::now(); |
| 2874 | |
| 2875 | // Load the target change to get its dependencies |
| 2876 | let _change = self.load_change(hash)?; |
| 2877 | |
| 2878 | // Get the view name |
| 2879 | let view_name = options.view.as_deref().unwrap_or(&self.current_view); |
| 2880 | |
| 2881 | if trace_insert { |
| 2882 | eprintln!( |
| 2883 | "[insert_change_rec] start hash={} view={}", |
| 2884 | &hash.to_base32()[..12], |
| 2885 | view_name, |
| 2886 | ); |
| 2887 | } |
| 2888 | |
| 2889 | // Get a read transaction to check what's already inserted |
| 2890 | let read_txn = self |
| 2891 | .pristine |
| 2892 | .read_txn() |
| 2893 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 2894 | |
| 2895 | let view = read_txn |
| 2896 | .get_view(view_name) |
| 2897 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 2898 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 2899 | name: view_name.to_string(), |
| 2900 | })?; |
| 2901 | |
| 2902 | // Collect every missing change (the target included) in dependency |
| 2903 | // order: a depth-first post-order over the dependency graph lists |
| 2904 | // each change after all of its dependencies. The previous |
| 2905 | // breadth-first list reversed was not topological (a dependency |
| 2906 | // listed after a sibling that needs it came out after that sibling), |
| 2907 | // so a closure referenced into a new view could apply a change |
| 2908 | // before the change its edges anchor to; the misanchored lines then |
| 2909 | // rendered twice (a branch seeded after merges rendered a merged |
| 2910 | // line both at the top and at the end of the file). |
| 2911 | let mut to_insert = Vec::new(); |
| 2912 | let mut visited = std::collections::HashSet::new(); |
| 2913 | let mut stack: Vec<(Hash, bool)> = vec![(*hash, false)]; |