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

Method create_overlay_view

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

Calls 15

ensure_workspace_dirFunction · 0.85
review_evidence_lockMethod · 0.80
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