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

Method open_readonly

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

414 /// let status = repo.status(StatusOptions::default())?;
415 /// ```
416 pub fn open_readonly<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> {
417 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path.as_ref()) {
418 return Self::open_sandbox(working_root, canonical, &view);
419 }
420 let root = Self::find_root(path.as_ref())?;
421 let dot_dir = root.join(DOT_DIR);
422
423 // Open the pristine database in read-only mode
424 let pristine = Arc::new(
425 Pristine::open_readonly(dot_dir.join("pristine.redb"))
426 .map_err(|e| RepositoryError::Database(e.to_string()))?,
427 );
428
429 // Read current view from config or use default
430 let current_view =
431 Self::read_current_view(&dot_dir).unwrap_or_else(|_| DEFAULT_STACK.to_string());
432
433 // Open the change store
434 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
435 .map_err(|e| RepositoryError::Database(e.to_string()))?;
436
437 let repository = Self {
438 root,
439 dot_dir,
440 current_view,
441 pristine,
442 change_store,
443 is_sandbox: false,
444 };
445 if repository.has_pending_deferred_tree_alignment() {
446 return Err(RepositoryError::InvalidOperation {
447 message: "repository view switch is still completing; retry with a writable repository open"
448 .to_string(),
449 });
450 }
451 Ok(repository)
452 }
453
454 /// Open an existing repository using a pre-opened `Pristine`.
455 ///

Callers

nothing calls this directly

Calls 3

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected