MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / insert_change_rec

Method insert_change_rec

atomic-repository/src/repository/insert.rs:1914–2034  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

1912 /// println!("Inserted {} changes", result.stats.changes_applied);
1913 /// ```
1914 pub fn insert_change_rec(
1915 &self,
1916 hash: &Hash,
1917 options: InsertOptions,
1918 ) -> Result<InsertOutcome, RepositoryError> {
1919 let trace_insert = std::env::var_os("ATOMIC_TRACE_INSERT").is_some();
1920 let t0 = std::time::Instant::now();
1921
1922 // Load the target change to get its dependencies
1923 let _change = self.load_change(hash)?;
1924
1925 // Get the view name
1926 let view_name = options.view.as_deref().unwrap_or(&self.current_view);
1927
1928 if trace_insert {
1929 eprintln!(
1930 "[insert_change_rec] start hash={} view={}",
1931 &hash.to_base32()[..12],
1932 view_name,
1933 );
1934 }
1935
1936 // Get a read transaction to check what's already inserted
1937 let read_txn = self
1938 .pristine
1939 .read_txn()
1940 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1941
1942 let view = read_txn
1943 .get_view(view_name)
1944 .map_err(|e| RepositoryError::Database(e.to_string()))?
1945 .ok_or_else(|| RepositoryError::ViewNotFound {
1946 name: view_name.to_string(),
1947 })?;
1948
1949 // Collect all needed changes (including the target)
1950 let mut to_insert = Vec::new();
1951 let mut visited = std::collections::HashSet::new();
1952 let mut queue = std::collections::VecDeque::new();
1953 queue.push_back(*hash);
1954
1955 while let Some(current_hash) = queue.pop_front() {
1956 if visited.contains(&current_hash) {
1957 continue;
1958 }
1959 visited.insert(current_hash);
1960
1961 // Check if already inserted
1962 if let Ok(Some(id)) = read_txn.get_internal(&current_hash) {
1963 if read_txn.get_change_seq(&view, id).ok().flatten().is_some() {
1964 continue; // Already inserted
1965 }
1966 }
1967
1968 // Load and queue dependencies
1969 let dep_change = self.load_change(&current_hash)?;
1970 for dep in dep_change.dependencies() {
1971 if !visited.contains(dep) {

Calls 15

read_txnMethod · 0.80
load_changeMethod · 0.45
get_viewMethod · 0.45
containsMethod · 0.45
insertMethod · 0.45
get_internalMethod · 0.45
get_change_seqMethod · 0.45
dependenciesMethod · 0.45
pushMethod · 0.45
reverseMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45