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)
| 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 | /// |
no test coverage detected