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

Method open_readonly

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

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

Callers

nothing calls this directly

Calls 2

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected