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

Method open_existing_once

atomic-repository/src/repository/mod.rs:719–770  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

717 }
718
719 fn open_existing_once(path: &Path) -> Result<Self, RepositoryError> {
720 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path) {
721 // CB-13D ::24 R1: the sandbox open runs the SAME recovery
722 // steps as the ordinary open_existing (which recovers
723 // unconditionally) — the sandbox path must not return before
724 // that gate.
725 let mut sandbox = Self::open_sandbox(working_root, canonical, &view)?;
726 let working_copy = sandbox.require_working_copy_id()?;
727 sandbox.fence_recovery_for_budget(working_copy, ReconcileEffectBudget::Command)?;
728 return Ok(sandbox);
729 }
730 let layout = working_copy::discover_layout(path)?;
731 let root = layout.working_root.clone();
732 let dot_dir = layout.common_dot_dir.clone();
733
734 let pristine = Arc::new(
735 Pristine::open_existing(ensure_database(&dot_dir)?).map_err(RepositoryError::from)?,
736 );
737 let (working_copy_id, current_view) =
738 working_copy::load_registered_identity(&pristine, &layout)?;
739
740 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
741 .map_err(|e| RepositoryError::Database(e.to_string()))?;
742
743 let mut repository = Self {
744 root,
745 dot_dir,
746 current_view,
747 pristine,
748 change_store,
749 is_sandbox: false,
750 semantic_closure_memo: Default::default(),
751 };
752 let operation_lock = repository.try_lock_operation(working_copy_id)?;
753 repository.recover_pending_deferred_tree_alignment_locked(&operation_lock)?;
754 repository.ensure_repository_operation_safe_for(&operation_lock)?;
755 if let OperationHeadState::Diverged(heads) =
756 repository.consolidate_operation_heads_locked(&operation_lock)?
757 {
758 return Err(RepositoryError::OperationHeadsDiverged {
759 scope: atomic_core::operation::OperationScope::WorkingCopy(working_copy_id)
760 .to_string(),
761 heads: heads.iter().map(ToString::to_string).collect(),
762 });
763 }
764 repository.recover_incomplete_operation(&operation_lock)?;
765 drop(operation_lock);
766 let (_id, authoritative_view) =
767 working_copy::load_registered_identity(&repository.pristine, &layout)?;
768 repository.current_view = authoritative_view;
769 Ok(repository)
770 }
771
772 /// Open an existing repository for a workspace transaction preflight.
773 ///

Callers

nothing calls this directly

Tested by

no test coverage detected