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

Method create_view

atomic-repository/src/repository/views.rs:72–124  ·  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

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

Calls 6

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