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

Method open_readonly

atomic-repository/src/repository/mod.rs:453–489  ·  view source on GitHub ↗

Open an existing repository in read-only mode. This method opens the repository without acquiring a write lock on the database, allowing concurrent read access from multiple processes. It's suitable for read-only operations like `status`, `diff`, `log`, and `change`. Use this method when you only need to query the repository state and don't need to make any modifications. This is especially usef

(path: P)

Source from the content-addressed store, hash-verified

451 /// let status = repo.status(StatusOptions::default())?;
452 /// ```
453 pub fn open_readonly<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> {
454 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path.as_ref()) {
455 return Self::open_sandbox(working_root, canonical, &view);
456 }
457 let root = Self::find_root(path.as_ref())?;
458 let dot_dir = root.join(DOT_DIR);
459
460 // Open the pristine database in read-only mode
461 let pristine = Arc::new(
462 Pristine::open_readonly(dot_dir.join("pristine.redb"))
463 .map_err(|e| RepositoryError::Database(e.to_string()))?,
464 );
465
466 // Read current view from config or use default
467 let current_view =
468 Self::read_current_view(&dot_dir).unwrap_or_else(|_| DEFAULT_STACK.to_string());
469
470 // Open the change store
471 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
472 .map_err(|e| RepositoryError::Database(e.to_string()))?;
473
474 let repository = Self {
475 root,
476 dot_dir,
477 current_view,
478 pristine,
479 change_store,
480 is_sandbox: false,
481 };
482 if repository.has_pending_deferred_tree_alignment() {
483 return Err(RepositoryError::InvalidOperation {
484 message: "repository view switch is still completing; retry with a writable repository open"
485 .to_string(),
486 });
487 }
488 Ok(repository)
489 }
490
491 /// Open an existing repository using a pre-opened `Pristine`.
492 ///

Callers

nothing calls this directly

Calls 3

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected