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

Method nearest_shared_ancestor

atomic-repository/src/repository/views.rs:361–398  ·  view source on GitHub ↗

Walk the parent chain from `view_name` and return the name of the first Shared view encountered. If `view_name` is itself Shared, it is returned immediately. This is used to determine the correct parent for newly created Draft views.

(&self, view_name: &str)

Source from the content-addressed store, hash-verified

359 /// it is returned immediately. This is used to determine the correct
360 /// parent for newly created Draft views.
361 pub fn nearest_shared_ancestor(&self, view_name: &str) -> Result<String, RepositoryError> {
362 let txn = self
363 .pristine
364 .read_txn()
365 .map_err(|e| RepositoryError::Database(e.to_string()))?;
366
367 let view = txn
368 .get_view(view_name)
369 .map_err(|e| RepositoryError::Database(e.to_string()))?
370 .ok_or_else(|| RepositoryError::ViewNotFound {
371 name: view_name.to_string(),
372 })?;
373
374 // Already Shared → use it directly.
375 if view.kind.is_shared() {
376 return Ok(view_name.to_string());
377 }
378
379 // Walk up the parent chain looking for a Shared ancestor.
380 let mut cursor = view.parent;
381 while let Some(parent_id) = cursor {
382 if let Some(parent) = txn
383 .get_view_by_id(parent_id)
384 .map_err(|e| RepositoryError::Database(e.to_string()))?
385 {
386 if parent.kind.is_shared() {
387 return Ok(parent.name.clone());
388 }
389 cursor = parent.parent;
390 } else {
391 break;
392 }
393 }
394
395 // Fallback: if no Shared ancestor found (shouldn't happen in
396 // normal use — dev is always Shared), use the current view.
397 Ok(view_name.to_string())
398 }
399
400 /// Create a new view that inherits changes from another view.
401 ///

Callers 2

runMethod · 0.80
create_overlay_viewMethod · 0.80

Calls 5

read_txnMethod · 0.80
is_sharedMethod · 0.80
get_viewMethod · 0.45
get_view_by_idMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected