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

Method open_existing

atomic-repository/src/repository/mod.rs:356–384  ·  view source on GitHub ↗

Open an existing repository without the table-init write lock. Like [`open`](Self::open) but uses [`Pristine::open_existing`] which skips the `begin_write()` table-initialization transaction. The returned repository still supports write operations — the write lock is deferred until `write_txn()` is actually called. Use this for short-lived processes (agent hooks, background jobs) where blocking

(path: P)

Source from the content-addressed store, hash-verified

354 /// Use this for short-lived processes (agent hooks, background jobs)
355 /// where blocking on the init write lock would hang the process.
356 pub fn open_existing<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> {
357 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path.as_ref()) {
358 return Self::open_sandbox(working_root, canonical, &view);
359 }
360 let root = Self::find_root(path.as_ref())?;
361 let dot_dir = root.join(DOT_DIR);
362
363 let pristine = Arc::new(
364 Pristine::open_existing(dot_dir.join("pristine.redb"))
365 .map_err(|e| RepositoryError::Database(e.to_string()))?,
366 );
367
368 let current_view =
369 Self::read_current_view(&dot_dir).unwrap_or_else(|_| DEFAULT_STACK.to_string());
370
371 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
372 .map_err(|e| RepositoryError::Database(e.to_string()))?;
373
374 let mut repository = Self {
375 root,
376 dot_dir,
377 current_view,
378 pristine,
379 change_store,
380 is_sandbox: false,
381 };
382 repository.recover_pending_deferred_tree_alignment()?;
383 Ok(repository)
384 }
385
386 /// Open an existing repository in read-only mode.
387 ///

Callers

nothing calls this directly

Calls 3

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected