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