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,
options: InsertOptions,
)
| 1967 | /// println!("Inserted {} changes", result.stats.changes_applied); |
| 1968 | /// ``` |
| 1969 | pub fn insert_change_rec( |
| 1970 | &self, |
| 1971 | hash: &Hash, |
| 1972 | options: InsertOptions, |
| 1973 | ) -> Result<InsertOutcome, RepositoryError> { |
| 1974 | let trace_insert = std::env::var_os("ATOMIC_TRACE_INSERT").is_some(); |
| 1975 | let t0 = std::time::Instant::now(); |
| 1976 | |
| 1977 | // Load the target change to get its dependencies |
| 1978 | let _change = self.load_change(hash)?; |
| 1979 | |
| 1980 | // Get the view name |
| 1981 | let view_name = options.view.as_deref().unwrap_or(&self.current_view); |
| 1982 | |
| 1983 | if trace_insert { |
| 1984 | eprintln!( |
| 1985 | "[insert_change_rec] start hash={} view={}", |
| 1986 | &hash.to_base32()[..12], |
| 1987 | view_name, |
| 1988 | ); |
| 1989 | } |
| 1990 | |
| 1991 | // Get a read transaction to check what's already inserted |
| 1992 | let read_txn = self |
| 1993 | .pristine |
| 1994 | .read_txn() |
| 1995 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1996 | |
| 1997 | let view = read_txn |
| 1998 | .get_view(view_name) |
| 1999 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 2000 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 2001 | name: view_name.to_string(), |
| 2002 | })?; |
| 2003 | |
| 2004 | // Collect all needed changes (including the target) |
| 2005 | let mut to_insert = Vec::new(); |
| 2006 | let mut visited = std::collections::HashSet::new(); |
| 2007 | let mut queue = std::collections::VecDeque::new(); |
| 2008 | queue.push_back(*hash); |
| 2009 | |
| 2010 | while let Some(current_hash) = queue.pop_front() { |
| 2011 | if visited.contains(¤t_hash) { |
| 2012 | continue; |
| 2013 | } |
| 2014 | visited.insert(current_hash); |
| 2015 | |
| 2016 | // Check if already inserted |
| 2017 | if let Ok(Some(id)) = read_txn.get_internal(¤t_hash) { |
| 2018 | if read_txn.get_change_seq(&view, id).ok().flatten().is_some() { |
| 2019 | continue; // Already inserted |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | // Load and queue dependencies |
| 2024 | let dep_change = self.load_change(¤t_hash)?; |
| 2025 | for dep in dep_change.dependencies() { |
| 2026 | if !visited.contains(dep) { |