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

Method nearest_shared_ancestor

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

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

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