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