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

Method nearest_shared_ancestor

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

195 /// it is returned immediately. This is used to determine the correct
196 /// parent for newly created Draft views.
197 pub fn nearest_shared_ancestor(&self, view_name: &str) -> Result<String, RepositoryError> {
198 let txn = self
199 .pristine
200 .read_txn()
201 .map_err(|e| RepositoryError::Database(e.to_string()))?;
202
203 let view = txn
204 .get_view(view_name)
205 .map_err(|e| RepositoryError::Database(e.to_string()))?
206 .ok_or_else(|| RepositoryError::ViewNotFound {
207 name: view_name.to_string(),
208 })?;
209
210 // Already Shared → use it directly.
211 if view.kind.is_shared() {
212 return Ok(view_name.to_string());
213 }
214
215 // Walk up the parent chain looking for a Shared ancestor.
216 let mut cursor = view.parent;
217 while let Some(parent_id) = cursor {
218 if let Some(parent) = txn
219 .get_view_by_id(parent_id)
220 .map_err(|e| RepositoryError::Database(e.to_string()))?
221 {
222 if parent.kind.is_shared() {
223 return Ok(parent.name.clone());
224 }
225 cursor = parent.parent;
226 } else {
227 break;
228 }
229 }
230
231 // Fallback: if no Shared ancestor found (shouldn't happen in
232 // normal use — dev is always Shared), use the current view.
233 Ok(view_name.to_string())
234 }
235
236 /// Create a new view that inherits changes from another view.
237 ///

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