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

Method open_readonly

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

407 /// let status = repo.status(StatusOptions::default())?;
408 /// ```
409 pub fn open_readonly<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> {
410 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path.as_ref()) {
411 return Self::open_sandbox(working_root, canonical, &view);
412 }
413 let root = Self::find_root(path.as_ref())?;
414 let dot_dir = root.join(DOT_DIR);
415
416 // Open the pristine database in read-only mode
417 let pristine = Arc::new(
418 Pristine::open_readonly(dot_dir.join("pristine.redb"))
419 .map_err(|e| RepositoryError::Database(e.to_string()))?,
420 );
421
422 // Read current view from config or use default
423 let current_view =
424 Self::read_current_view(&dot_dir).unwrap_or_else(|_| DEFAULT_STACK.to_string());
425
426 // Open the change store
427 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
428 .map_err(|e| RepositoryError::Database(e.to_string()))?;
429
430 Ok(Self {
431 root,
432 dot_dir,
433 current_view,
434 pristine,
435 change_store,
436 is_sandbox: false,
437 })
438 }
439
440 /// Open an existing repository using a pre-opened `Pristine`.
441 ///

Callers

nothing calls this directly

Calls 2

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected