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)
| 208 | /// it is returned immediately. This is used to determine the correct |
| 209 | /// parent for newly created Draft views. |
| 210 | pub fn nearest_shared_ancestor(&self, view_name: &str) -> Result<String, RepositoryError> { |
| 211 | let txn = self |
| 212 | .pristine |
| 213 | .read_txn() |
| 214 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 215 | |
| 216 | let view = txn |
| 217 | .get_view(view_name) |
| 218 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 219 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 220 | name: view_name.to_string(), |
| 221 | })?; |
| 222 | |
| 223 | // Already Shared → use it directly. |
| 224 | if view.kind.is_shared() { |
| 225 | return Ok(view_name.to_string()); |
| 226 | } |
| 227 | |
| 228 | // Walk up the parent chain looking for a Shared ancestor. |
| 229 | let mut cursor = view.parent; |
| 230 | while let Some(parent_id) = cursor { |
| 231 | if let Some(parent) = txn |
| 232 | .get_view_by_id(parent_id) |
| 233 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 234 | { |
| 235 | if parent.kind.is_shared() { |
| 236 | return Ok(parent.name.clone()); |
| 237 | } |
| 238 | cursor = parent.parent; |
| 239 | } else { |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // Fallback: if no Shared ancestor found (shouldn't happen in |
| 245 | // normal use — dev is always Shared), use the current view. |
| 246 | Ok(view_name.to_string()) |
| 247 | } |
| 248 | |
| 249 | /// Create a new view that inherits changes from another view. |
| 250 | /// |
no test coverage detected