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)
| 309 | /// |
| 310 | /// Returns an error if no repository is found. |
| 311 | pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> { |
| 312 | if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path.as_ref()) { |
| 313 | return Self::open_sandbox(working_root, canonical, &view); |
| 314 | } |
| 315 | let root = Self::find_root(path.as_ref())?; |
| 316 | let dot_dir = root.join(DOT_DIR); |
| 317 | |
| 318 | // Open the pristine database |
| 319 | let pristine = Arc::new( |
| 320 | Pristine::open(dot_dir.join("pristine.redb")) |
| 321 | .map_err(|e| RepositoryError::Database(e.to_string()))?, |
| 322 | ); |
| 323 | |
| 324 | // Read current view from config or use default |
| 325 | let current_view = |
| 326 | Self::read_current_view(&dot_dir).unwrap_or_else(|_| DEFAULT_STACK.to_string()); |
| 327 | |
| 328 | // Open the change store |
| 329 | let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY) |
| 330 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 331 | |
| 332 | Ok(Self { |
| 333 | root, |
| 334 | dot_dir, |
| 335 | current_view, |
| 336 | pristine, |
| 337 | change_store, |
| 338 | is_sandbox: false, |
| 339 | }) |
| 340 | } |
| 341 | |
| 342 | /// Open an existing repository without the table-init write lock. |
| 343 | /// |
nothing calls this directly
no test coverage detected