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