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

Method create_view

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

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

Calls 6

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