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

Method nearest_shared_ancestor

atomic-repository/src/repository/views.rs:330–367  ·  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

328 /// it is returned immediately. This is used to determine the correct
329 /// parent for newly created Draft views.
330 pub fn nearest_shared_ancestor(&self, view_name: &str) -> Result<String, RepositoryError> {
331 let txn = self
332 .pristine
333 .read_txn()
334 .map_err(|e| RepositoryError::Database(e.to_string()))?;
335
336 let view = txn
337 .get_view(view_name)
338 .map_err(|e| RepositoryError::Database(e.to_string()))?
339 .ok_or_else(|| RepositoryError::ViewNotFound {
340 name: view_name.to_string(),
341 })?;
342
343 // Already Shared → use it directly.
344 if view.kind.is_shared() {
345 return Ok(view_name.to_string());
346 }
347
348 // Walk up the parent chain looking for a Shared ancestor.
349 let mut cursor = view.parent;
350 while let Some(parent_id) = cursor {
351 if let Some(parent) = txn
352 .get_view_by_id(parent_id)
353 .map_err(|e| RepositoryError::Database(e.to_string()))?
354 {
355 if parent.kind.is_shared() {
356 return Ok(parent.name.clone());
357 }
358 cursor = parent.parent;
359 } else {
360 break;
361 }
362 }
363
364 // Fallback: if no Shared ancestor found (shouldn't happen in
365 // normal use — dev is always Shared), use the current view.
366 Ok(view_name.to_string())
367 }
368
369 /// Create a new view that inherits changes from another view.
370 ///

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