Open an existing repository. This searches for a `.atomic` directory starting from the given path and walking up to parent directories. # Arguments `path` - A path inside the repository (or the repository root) # Errors Returns an error if no repository is found.
(path: P)
| 349 | /// |
| 350 | /// Returns an error if no repository is found. |
| 351 | pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> { |
| 352 | if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path.as_ref()) { |
| 353 | return Self::open_sandbox(working_root, canonical, &view); |
| 354 | } |
| 355 | let root = Self::find_root(path.as_ref())?; |
| 356 | let dot_dir = root.join(DOT_DIR); |
| 357 | |
| 358 | // Open the pristine database |
| 359 | let pristine = Arc::new( |
| 360 | Pristine::open(dot_dir.join("pristine.redb")) |
| 361 | .map_err(|e| RepositoryError::Database(e.to_string()))?, |
| 362 | ); |
| 363 | |
| 364 | // Read current view from config or use default |
| 365 | let current_view = |
| 366 | Self::read_current_view(&dot_dir).unwrap_or_else(|_| DEFAULT_STACK.to_string()); |
| 367 | |
| 368 | // Open the change store |
| 369 | let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY) |
| 370 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 371 | |
| 372 | let mut repository = Self { |
| 373 | root, |
| 374 | dot_dir, |
| 375 | current_view, |
| 376 | pristine, |
| 377 | change_store, |
| 378 | is_sandbox: false, |
| 379 | }; |
| 380 | repository.recover_pending_deferred_tree_alignment()?; |
| 381 | Ok(repository) |
| 382 | } |
| 383 | |
| 384 | /// Open an existing repository without the table-init write lock. |
| 385 | /// |
no test coverage detected