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

Method open_readonly

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

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

Callers

nothing calls this directly

Calls 3

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected