Create a view with an explicit scope and optional named parent. The view's change log starts empty; this only establishes identity.
(
&mut self,
name: &str,
scope: ViewScope,
parent_name: Option<&str>,
)
| 618 | /// |
| 619 | /// The view's change log starts empty; this only establishes identity. |
| 620 | fn create_view_with_identity( |
| 621 | &mut self, |
| 622 | name: &str, |
| 623 | scope: ViewScope, |
| 624 | parent_name: Option<&str>, |
| 625 | ) -> Result<(), RepositoryError> { |
| 626 | ensure_workspace_dir(&self.dot_dir, name)?; |
| 627 | |
| 628 | let mut txn = self |
| 629 | .pristine |
| 630 | .write_txn() |
| 631 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 632 | |
| 633 | if txn |
| 634 | .get_view(name) |
| 635 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 636 | .is_some() |
| 637 | { |
| 638 | return Err(RepositoryError::ViewAlreadyExists { |
| 639 | name: name.to_string(), |
| 640 | }); |
| 641 | } |
| 642 | |
| 643 | let parent_id = match parent_name { |
| 644 | Some(p) => Some( |
| 645 | txn.get_view(p) |
| 646 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 647 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 648 | name: p.to_string(), |
| 649 | })? |
| 650 | .id, |
| 651 | ), |
| 652 | None => None, |
| 653 | }; |
| 654 | |
| 655 | txn.create_view(name, scope, parent_id) |
| 656 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 657 | |
| 658 | txn.commit() |
| 659 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 660 | |
| 661 | Ok(()) |
| 662 | } |
| 663 | |
| 664 | /// Export a view's complete identity as a [`ViewManifest`]. |
| 665 | /// |
no test coverage detected