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

Method nearest_shared_ancestor

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

263 /// it is returned immediately. This is used to determine the correct
264 /// parent for newly created Draft views.
265 pub fn nearest_shared_ancestor(&self, view_name: &str) -> Result<String, RepositoryError> {
266 let txn = self
267 .pristine
268 .read_txn()
269 .map_err(|e| RepositoryError::Database(e.to_string()))?;
270
271 let view = txn
272 .get_view(view_name)
273 .map_err(|e| RepositoryError::Database(e.to_string()))?
274 .ok_or_else(|| RepositoryError::ViewNotFound {
275 name: view_name.to_string(),
276 })?;
277
278 // Already Shared → use it directly.
279 if view.kind.is_shared() {
280 return Ok(view_name.to_string());
281 }
282
283 // Walk up the parent chain looking for a Shared ancestor.
284 let mut cursor = view.parent;
285 while let Some(parent_id) = cursor {
286 if let Some(parent) = txn
287 .get_view_by_id(parent_id)
288 .map_err(|e| RepositoryError::Database(e.to_string()))?
289 {
290 if parent.kind.is_shared() {
291 return Ok(parent.name.clone());
292 }
293 cursor = parent.parent;
294 } else {
295 break;
296 }
297 }
298
299 // Fallback: if no Shared ancestor found (shouldn't happen in
300 // normal use — dev is always Shared), use the current view.
301 Ok(view_name.to_string())
302 }
303
304 /// Create a new view that inherits changes from another view.
305 ///

Callers 1

create_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