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

Method open_readonly

atomic-repository/src/repository/mod.rs:463–498  ·  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

461 /// let status = repo.status(StatusOptions::default())?;
462 /// ```
463 pub fn open_readonly<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> {
464 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path.as_ref()) {
465 return Self::open_sandbox_readonly(working_root, canonical, &view);
466 }
467 let root = Self::find_root(path.as_ref())?;
468 let dot_dir = root.join(DOT_DIR);
469
470 // Open the pristine database in read-only mode
471 let pristine = Arc::new(
472 Pristine::open_readonly(dot_dir.join("pristine.redb"))
473 .map_err(RepositoryError::from)?,
474 );
475
476 // Read current view from config or use default
477 let current_view =
478 Self::read_current_view(&dot_dir).unwrap_or_else(|_| DEFAULT_STACK.to_string());
479
480 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
481 .map_err(|e| RepositoryError::Database(e.to_string()))?;
482
483 let repository = Self {
484 root,
485 dot_dir,
486 current_view,
487 pristine,
488 change_store,
489 is_sandbox: false,
490 };
491 if repository.has_pending_deferred_tree_alignment() {
492 return Err(RepositoryError::InvalidOperation {
493 message: "repository view switch is still completing; retry with a writable repository open"
494 .to_string(),
495 });
496 }
497 Ok(repository)
498 }
499
500 /// Open for a short-lived writer, waiting at most `timeout` for an
501 /// incompatible process handle to close. Other errors return immediately.

Callers

nothing calls this directly

Calls 3

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected