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

Method open

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

Open an existing repository. This searches for a `.atomic` directory starting from the given path and walking up to parent directories. # Arguments `path` - A path inside the repository (or the repository root) # Errors Returns an error if no repository is found.

(path: P)

Source from the content-addressed store, hash-verified

314 ///
315 /// Returns an error if no repository is found.
316 pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> {
317 if let Some((working_root, canonical, view)) = sandbox::detect_sandbox(path.as_ref()) {
318 return Self::open_sandbox(working_root, canonical, &view);
319 }
320 let root = Self::find_root(path.as_ref())?;
321 let dot_dir = root.join(DOT_DIR);
322
323 // Open the pristine database
324 let pristine = Arc::new(
325 Pristine::open(dot_dir.join("pristine.redb"))
326 .map_err(|e| RepositoryError::Database(e.to_string()))?,
327 );
328
329 // Read current view from config or use default
330 let current_view =
331 Self::read_current_view(&dot_dir).unwrap_or_else(|_| DEFAULT_STACK.to_string());
332
333 // Open the change store
334 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
335 .map_err(|e| RepositoryError::Database(e.to_string()))?;
336
337 let mut repository = Self {
338 root,
339 dot_dir,
340 current_view,
341 pristine,
342 change_store,
343 is_sandbox: false,
344 };
345 repository.recover_pending_deferred_tree_alignment()?;
346 Ok(repository)
347 }
348
349 /// Open an existing repository without the table-init write lock.
350 ///

Callers 1

Calls 3

detect_sandboxFunction · 0.85
as_refMethod · 0.80

Tested by

no test coverage detected