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

Method write_import_graph_change

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

Save and apply an already-built git-import graph change. This bypasses record/globalize and eager CRDT table writes. The caller has already compiled Git's snapshot delta into line-level graph ops. `preserve_existing_tree_paths` keeps deletions and renames graph-only while a different view owns the materialized working copy.

(
        &self,
        change: Change,
        deleted_paths: &[String],
        preserve_existing_tree_paths: bool,
        _verified: &VerifiedProspectiveEquivalence,
        options: InsertOption

Source from the content-addressed store, hash-verified

1638 /// `preserve_existing_tree_paths` keeps deletions and renames graph-only
1639 /// while a different view owns the materialized working copy.
1640 pub fn write_import_graph_change(
1641 &self,
1642 change: Change,
1643 deleted_paths: &[String],
1644 preserve_existing_tree_paths: bool,
1645 _verified: &VerifiedProspectiveEquivalence,
1646 options: InsertOptions,
1647 ) -> Result<ImportWriteOutcome, RepositoryError> {
1648 validate_import_deleted_paths(&change, deleted_paths)?;
1649 let mut timings = ImportWriteTimings::default();
1650 let view_name = options.view.as_deref().unwrap_or(&self.current_view);
1651 self.pristine
1652 .require_repository_capability(CHANGE_FORMAT_VNEXT_CAPABILITY)
1653 .map_err(RepositoryError::from)?;
1654
1655 let mut txn = self
1656 .pristine
1657 .write_txn()
1658 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1659
1660 let assemble_start = std::time::Instant::now();
1661 let mut v3_bytes = Vec::new();
1662 let hash = change
1663 .serialize(&mut v3_bytes)
1664 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1665 let (final_change, verified_hash) = Change::deserialize(&mut v3_bytes.as_slice())
1666 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1667 debug_assert_eq!(hash, verified_hash);
1668 timings.assemble_ms = assemble_start.elapsed().as_millis();
1669
1670 // Idempotency guard for the single global GRAPH.
1671 //
1672 // A change is applied to the graph exactly once; views merely
1673 // reference it. Because import registers and applies a change in the
1674 // same transaction, an already-registered change has already been
1675 // applied — re-running its graph ops here would allocate a second
1676 // inode for every added path and manufacture a spurious name/order
1677 // conflict on materialize. This is exactly what `git import --all`
1678 // hits: a commit shared by two branches (a common ancestor) is
1679 // imported once per branch. Reference the already-applied change into
1680 // the target view instead — the same O(1) VIEW_CHANGES metadata
1681 // operation `insert` performs — rather than re-applying it.
1682 if let Some(change_id) = txn
1683 .get_internal(&hash)
1684 .map_err(|e| RepositoryError::Database(e.to_string()))?
1685 {
1686 use atomic_core::apply::compute_new_state;
1687
1688 txn.put_change_deps(change_id, final_change.dependencies())
1689 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1690 let tree_projection = self.plan_tree_projection(
1691 &mut txn,
1692 change_id,
1693 hash,
1694 &final_change,
1695 deleted_paths,
1696 preserve_existing_tree_paths,
1697 )?;

Calls 15

filter_missing_in_viewFunction · 0.85
compute_new_stateFunction · 0.85
write_change_to_graphFunction · 0.85
write_txnMethod · 0.80
put_change_depsMethod · 0.80
plan_tree_projectionMethod · 0.80
apply_prerequisitesMethod · 0.80
open_or_create_viewMethod · 0.80
put_changeMethod · 0.80