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

Method create_overlay_view

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

Create one view — the ONLY creation concept atomic has. A view is a **filter over the global graph**: every change and node a view exposes already lives in the graph, and the view merely selects which changes it exposes. Creation therefore has exactly two parameters: - `parent_name` — the overlay-chain anchor. Draft views expose their own change-log PLUS the parent's effective set (recursively b

(
        &mut self,
        name: &str,
        parent_name: Option<&str>,
        seed_from: Option<&str>,
    )

Source from the content-addressed store, hash-verified

110 /// `create_view` and `create_view_from` are thin wrappers around this
111 /// single concept.
112 pub fn create_overlay_view(
113 &mut self,
114 name: &str,
115 parent_name: Option<&str>,
116 seed_from: Option<&str>,
117 ) -> Result<(), RepositoryError> {
118 self.ensure_project_identity(atomic_core::kg::project_id::MintReason::Upgrade)?;
119 // The overlay chain is anchored on the nearest Shared ancestor of the
120 // current view unless a parent is given. Using the nearest SHARED
121 // ancestor (instead of the current view directly) prevents sibling
122 // Draft views from seeing each other's edges through the overlay.
123 let anchor = match parent_name {
124 Some(p) => p.to_string(),
125 None => self.nearest_shared_ancestor(&self.current_view.clone())?,
126 };
127
128 ensure_workspace_dir(&self.dot_dir, name)?;
129
130 let mut txn = self
131 .pristine
132 .write_txn()
133 .map_err(|e| RepositoryError::Database(e.to_string()))?;
134
135 if txn
136 .get_view(name)
137 .map_err(|e| RepositoryError::Database(e.to_string()))?
138 .is_some()
139 {
140 return Err(RepositoryError::ViewAlreadyExists {
141 name: name.to_string(),
142 });
143 }
144
145 let anchor_view = txn
146 .get_view(&anchor)
147 .map_err(|e| RepositoryError::Database(e.to_string()))?
148 .ok_or_else(|| RepositoryError::ViewNotFound {
149 name: anchor.clone(),
150 })?;
151
152 let mut new_view = txn
153 .create_view(name, ViewScope::Draft, Some(anchor_view.id))
154 .map_err(|e| RepositoryError::Database(e.to_string()))?;
155
156 // Seed the filter: copy the source view's change-set MEMBERSHIP into
157 // the new view's own log. This does NOT re-insert hunks — the edges
158 // already exist in GRAPH; the new view simply selects them.
159 if let Some(source_name) = seed_from {
160 let source_view = txn
161 .get_view(source_name)
162 .map_err(|e| RepositoryError::Database(e.to_string()))?
163 .ok_or_else(|| RepositoryError::ViewNotFound {
164 name: source_name.to_string(),
165 })?;
166
167 // Collect membership first so the iterator is dropped before the
168 // mutable put_change writes below.
169 let membership: Vec<(NodeId, Hash)> = {

Calls 15

ensure_workspace_dirFunction · 0.85
write_txnMethod · 0.80
put_changeMethod · 0.80
update_viewMethod · 0.80
kg_writes_enabledMethod · 0.80
project_view_kgMethod · 0.80
cloneMethod · 0.45
get_viewMethod · 0.45
create_viewMethod · 0.45