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

Method write_recorded

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

Write a recorded change to the repository. This method inserts a change that was just recorded, updating both the graph and the tree tables. It's the integration point between recording and inserting. Unlike `insert_change`, this method: - Takes the change directly (doesn't load from store) - Updates tree tables for FileAdd hunks - Assigns new inodes to added files # Arguments `outcome` - The

(
        &self,
        outcome: &RecordOutcome,
        mut options: InsertOptions,
    )

Source from the content-addressed store, hash-verified

2016 /// println!("Inserted with state: {}", apply_outcome.new_state.to_base32());
2017 /// ```
2018 pub fn write_recorded(
2019 &self,
2020 outcome: &RecordOutcome,
2021 mut options: InsertOptions,
2022 ) -> Result<InsertOutcome, RepositoryError> {
2023 let trace_record = std::env::var_os("ATOMIC_TRACE_RECORD").is_some();
2024 let change = outcome.change();
2025 let hash = outcome.hash();
2026
2027 // A freshly-recorded change is applied to the view it was recorded on.
2028 // Its dependency closure is complete by construction, so it cannot
2029 // produce zombie or missing-context conflicts. Disable conflict
2030 // detection to skip the per-hunk zombie/deleted-context graph scans
2031 // (the dominant apply cost on large changes); the graph written is
2032 // identical, only the (empty) conflict report is skipped.
2033 options.track_conflicts = false;
2034
2035 // Get write transaction
2036 let mut txn = self
2037 .pristine
2038 .write_txn()
2039 .map_err(|e| RepositoryError::Database(e.to_string()))?;
2040
2041 // Register the change to get an internal ID
2042 let change_id = txn
2043 .register_change(hash)
2044 .map_err(|e| RepositoryError::Database(e.to_string()))?;
2045 txn.put_change_deps(change_id, change.dependencies())
2046 .map_err(|e| RepositoryError::Database(e.to_string()))?;
2047
2048 // Determine which view to use
2049 let view_name = options.view.as_deref().unwrap_or(&self.current_view);
2050 let preserve_existing_tree_paths = view_name != self.current_view;
2051 let tree_ops = collect_tree_ops(&txn, *hash, change, outcome.deleted_files())?;
2052
2053 // Before applying atoms, set up tree entries for FileAdd hunks.
2054 // This creates the inode→position and path→inode mappings needed
2055 // for the graph operations.
2056 //
2057 // Note: put_tree creates both TREE and REV_TREE entries.
2058 // put_inode creates both INODES and REV_INODES entries.
2059 for graph_op in change.hunks() {
2060 match graph_op {
2061 GraphOp::FileAdd {
2062 add_inode, path, ..
2063 } => {
2064 // Allocate a new inode for this file
2065 let new_inode = txn
2066 .alloc_inode()
2067 .map_err(|e| RepositoryError::Database(e.to_string()))?;
2068
2069 // The inode span position is relative to this change.
2070 // Since add_inode.start is a ChangePosition within this change's content,
2071 // we create an internal position using the change_id we just registered.
2072 let inode_position = Position::new(change_id, add_inode.start);
2073
2074 // Add to tree tables:
2075 // - put_tree: path ↔ inode (TREE and REV_TREE)

Calls 15

collect_tree_opsFunction · 0.85
explicit_emptyFunction · 0.85
is_file_only_on_viewFunction · 0.85
write_change_to_graphFunction · 0.85
write_txnMethod · 0.80
register_changeMethod · 0.80
put_change_depsMethod · 0.80
put_treeMethod · 0.80
put_inodeMethod · 0.80
put_directoryMethod · 0.80
del_treeMethod · 0.80
del_inodeMethod · 0.80