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>,
)
| 673 | /// |
| 674 | /// The view's change log starts empty; this only establishes identity. |
| 675 | fn create_view_with_identity( |
| 676 | &mut self, |
| 677 | name: &str, |
| 678 | scope: ViewScope, |
| 679 | parent_name: Option<&str>, |
| 680 | ) -> Result<(), RepositoryError> { |
| 681 | ensure_workspace_dir(&self.dot_dir, name)?; |
| 682 | |
| 683 | let mut txn = self |
| 684 | .pristine |
| 685 | .write_txn() |
| 686 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 687 | |
| 688 | if txn |
| 689 | .get_view(name) |
| 690 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 691 | .is_some() |
| 692 | { |
| 693 | return Err(RepositoryError::ViewAlreadyExists { |
| 694 | name: name.to_string(), |
| 695 | }); |
| 696 | } |
| 697 | |
| 698 | let parent_id = match parent_name { |
| 699 | Some(p) => Some( |
| 700 | txn.get_view(p) |
| 701 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 702 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 703 | name: p.to_string(), |
| 704 | })? |
| 705 | .id, |
| 706 | ), |
| 707 | None => None, |
| 708 | }; |
| 709 | |
| 710 | txn.create_view(name, scope, parent_id) |
| 711 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 712 | |
| 713 | txn.commit() |
| 714 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 715 | |
| 716 | Ok(()) |
| 717 | } |
| 718 | |
| 719 | /// Export a view's complete identity as a [`ViewManifest`]. |
| 720 | /// |
no test coverage detected