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,
)
| 1861 | /// println!("Inserted {} changes", result.stats.changes_applied); |
| 1862 | /// ``` |
| 1863 | pub fn insert_change_rec( |
| 1864 | &self, |
| 1865 | hash: &Hash, |
| 1866 | options: InsertOptions, |
| 1867 | ) -> Result<InsertOutcome, RepositoryError> { |
| 1868 | let trace_insert = std::env::var_os("ATOMIC_TRACE_INSERT").is_some(); |
| 1869 | let t0 = std::time::Instant::now(); |
| 1870 | |
| 1871 | // Load the target change to get its dependencies |
| 1872 | let _change = self.load_change(hash)?; |
| 1873 | |
| 1874 | // Get the view name |
| 1875 | let view_name = options.view.as_deref().unwrap_or(&self.current_view); |
| 1876 | |
| 1877 | if trace_insert { |
| 1878 | eprintln!( |
| 1879 | "[insert_change_rec] start hash={} view={}", |
| 1880 | &hash.to_base32()[..12], |
| 1881 | view_name, |
| 1882 | ); |
| 1883 | } |
| 1884 | |
| 1885 | // Get a read transaction to check what's already inserted |
| 1886 | let read_txn = self |
| 1887 | .pristine |
| 1888 | .read_txn() |
| 1889 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1890 | |
| 1891 | let view = read_txn |
| 1892 | .get_view(view_name) |
| 1893 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 1894 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 1895 | name: view_name.to_string(), |
| 1896 | })?; |
| 1897 | |
| 1898 | // Collect all needed changes (including the target) |
| 1899 | let mut to_insert = Vec::new(); |
| 1900 | let mut visited = std::collections::HashSet::new(); |
| 1901 | let mut queue = std::collections::VecDeque::new(); |
| 1902 | queue.push_back(*hash); |
| 1903 | |
| 1904 | while let Some(current_hash) = queue.pop_front() { |
| 1905 | if visited.contains(¤t_hash) { |
| 1906 | continue; |
| 1907 | } |
| 1908 | visited.insert(current_hash); |
| 1909 | |
| 1910 | // Check if already inserted |
| 1911 | if let Ok(Some(id)) = read_txn.get_internal(¤t_hash) { |
| 1912 | if read_txn.get_change_seq(&view, id).ok().flatten().is_some() { |
| 1913 | continue; // Already inserted |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | // Load and queue dependencies |
| 1918 | let dep_change = self.load_change(¤t_hash)?; |
| 1919 | for dep in dep_change.dependencies() { |
| 1920 | if !visited.contains(dep) { |
no test coverage detected