MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / create_view

Method create_view

atomic-repository/src/repository/views.rs:68–120  ·  view source on GitHub ↗

Create a new view. # Arguments `name` - The name of the view to create # Errors Returns an error if: - The view already exists - The database operation fails

(&mut self, name: &str)

Source from the content-addressed store, hash-verified

66 /// - The view already exists
67 /// - The database operation fails
68 pub fn create_view(&mut self, name: &str) -> Result<(), RepositoryError> {
69 // Create the workspace directory for this view.
70 ensure_workspace_dir(&self.dot_dir, name)?;
71
72 // Create a **Draft** view parented on the nearest Shared
73 // ancestor of the current view. The change log starts EMPTY —
74 // no changes are inherited automatically.
75 //
76 // The parent link gives the view read-access to the shared
77 // graph content (via the overlay chain) so that `record` can
78 // compute diffs against the existing state. But no files are
79 // *materialised* on disk until changes are explicitly inserted
80 // into this view (which copies them into the view's change log).
81 //
82 // This means:
83 // `view new feature` → empty workspace, no files
84 // `insert from-view dev feature` → inherits dev's files
85 //
86 // Using the nearest Shared ancestor (instead of the current
87 // view directly) prevents sibling Draft views from seeing
88 // each other's edges through the overlay chain.
89 let parent_name = self.nearest_shared_ancestor(&self.current_view.clone())?;
90
91 let mut txn = self
92 .pristine
93 .write_txn()
94 .map_err(|e| RepositoryError::Database(e.to_string()))?;
95
96 if txn
97 .get_view(name)
98 .map_err(|e| RepositoryError::Database(e.to_string()))?
99 .is_some()
100 {
101 return Err(RepositoryError::ViewAlreadyExists {
102 name: name.to_string(),
103 });
104 }
105
106 let parent_view = txn
107 .get_view(&parent_name)
108 .map_err(|e| RepositoryError::Database(e.to_string()))?
109 .ok_or_else(|| RepositoryError::ViewNotFound {
110 name: parent_name.clone(),
111 })?;
112
113 txn.create_view(name, ViewScope::Draft, Some(parent_view.id))
114 .map_err(|e| RepositoryError::Database(e.to_string()))?;
115
116 txn.commit()
117 .map_err(|e| RepositoryError::Database(e.to_string()))?;
118
119 Ok(())
120 }
121
122 /// Create a new Shared view with no parent.
123 ///

Calls 6

ensure_workspace_dirFunction · 0.85
write_txnMethod · 0.80
commitMethod · 0.80
cloneMethod · 0.45
get_viewMethod · 0.45