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

Method open_existing

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

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

Callers

nothing calls this directly

Calls 3

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected