Open an existing repository using a pre-opened `Pristine`. This constructor is used by the storage server to share a single `Pristine` (redb `Database`) handle across concurrent requests to the same project. Sharing the handle ensures every write transaction sees the committed state of prior transactions — opening a fresh `Database` per request can see stale snapshots. # Requirements The provi
(
path: P,
pristine: Arc<Pristine>,
)
| 1041 | /// repository will silently couple one repo's configuration and |
| 1042 | /// change store with another repo's database, leading to corruption. |
| 1043 | pub fn open_with_pristine<P: AsRef<Path>>( |
| 1044 | path: P, |
| 1045 | pristine: Arc<Pristine>, |
| 1046 | ) -> Result<Self, RepositoryError> { |
| 1047 | let mut layout = working_copy::discover_layout(path.as_ref())?; |
| 1048 | pristine |
| 1049 | .ensure_supported_repository_capabilities() |
| 1050 | .map_err(RepositoryError::from)?; |
| 1051 | working_copy::ensure_repository_pointer(&layout)?; |
| 1052 | layout.pointer_needs_write = false; |
| 1053 | let root = layout.working_root.clone(); |
| 1054 | let dot_dir = layout.common_dot_dir.clone(); |
| 1055 | let initial_view = |
| 1056 | Self::read_legacy_current_view(&layout.working_copy_dot_dir, &layout.common_dot_dir)?; |
| 1057 | let (working_copy_id, current_view) = |
| 1058 | working_copy::migrate_identity(&pristine, &layout, &initial_view)?; |
| 1059 | |
| 1060 | let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY) |
| 1061 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 1062 | |
| 1063 | let mut repository = Self { |
| 1064 | root, |
| 1065 | dot_dir, |
| 1066 | current_view, |
| 1067 | pristine, |
| 1068 | change_store, |
| 1069 | is_sandbox: false, |
| 1070 | semantic_closure_memo: Default::default(), |
| 1071 | }; |
| 1072 | let operation_lock = repository.try_lock_operation(working_copy_id)?; |
| 1073 | repository.recover_pending_deferred_tree_alignment_locked(&operation_lock)?; |
| 1074 | repository.ensure_repository_operation_safe_for(&operation_lock)?; |
| 1075 | if let OperationHeadState::Diverged(heads) = |
| 1076 | repository.consolidate_operation_heads_locked(&operation_lock)? |
| 1077 | { |
| 1078 | return Err(RepositoryError::OperationHeadsDiverged { |
| 1079 | scope: atomic_core::operation::OperationScope::WorkingCopy(working_copy_id) |
| 1080 | .to_string(), |
| 1081 | heads: heads.iter().map(ToString::to_string).collect(), |
| 1082 | }); |
| 1083 | } |
| 1084 | repository.recover_incomplete_operation(&operation_lock)?; |
| 1085 | drop(operation_lock); |
| 1086 | let (_id, authoritative_view) = |
| 1087 | working_copy::load_registered_identity(&repository.pristine, &layout)?; |
| 1088 | repository.current_view = authoritative_view.clone(); |
| 1089 | working_copy::write_current_view_compatibility( |
| 1090 | &layout.working_copy_dot_dir, |
| 1091 | &authoritative_view, |
| 1092 | )?; |
| 1093 | Ok(repository) |
| 1094 | } |
| 1095 | |
| 1096 | /// Find the repository root by searching for .atomic directory. |
| 1097 | /// |
nothing calls this directly
no test coverage detected