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

Method create_view_from

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

Create a new view that inherits changes from another view. This creates a new view and copies all changes from the source view to the new view. The new view will have the same content state as the source view at the time of creation. # Arguments `name` - The name of the new view to create `from_view` - The name of the view to inherit changes from # Errors Returns an error if: - The new view a

(&mut self, name: &str, from_view: &str)

Source from the content-addressed store, hash-verified

263 /// repo.create_view_from("feature", "dev")?;
264 /// ```
265 pub fn create_view_from(&mut self, name: &str, from_view: &str) -> Result<(), RepositoryError> {
266 let mut txn = self
267 .pristine
268 .write_txn()
269 .map_err(|e| RepositoryError::Database(e.to_string()))?;
270
271 // Check if the new view already exists
272 if txn
273 .get_view(name)
274 .map_err(|e| RepositoryError::Database(e.to_string()))?
275 .is_some()
276 {
277 return Err(RepositoryError::ViewAlreadyExists {
278 name: name.to_string(),
279 });
280 }
281
282 // Get the source view
283 let source_view = txn
284 .get_view(from_view)
285 .map_err(|e| RepositoryError::Database(e.to_string()))?
286 .ok_or_else(|| RepositoryError::ViewNotFound {
287 name: from_view.to_string(),
288 })?;
289
290 let source_id = source_view.id;
291
292 // Collect all changes from the source view
293 let changes: Vec<(NodeId, Hash)> = {
294 let iter = txn
295 .iter_changes(&source_view, 0)
296 .map_err(|e| RepositoryError::Database(e.to_string()))?;
297
298 let mut result = Vec::new();
299 for item in iter {
300 let (_seq, node_id, _merkle) =
301 item.map_err(|e| RepositoryError::Database(e.to_string()))?;
302 let hash = txn
303 .get_external(node_id)
304 .map_err(|e| RepositoryError::Database(e.to_string()))?
305 .ok_or_else(|| {
306 RepositoryError::Database(format!(
307 "Change {} has no external hash",
308 node_id.0
309 ))
310 })?;
311 result.push((node_id, hash));
312 }
313 result
314 };
315
316 // Create the new view as a **Draft** view parented on the
317 // source view. Draft views write edges to GRAPH like all
318 // views, but use a change filter for isolation. The parent
319 // link means the view chain includes the source's content.
320 // Create workspace directory for the new view.
321 ensure_workspace_dir(&self.dot_dir, name)?;
322

Calls 10

ensure_workspace_dirFunction · 0.85
write_txnMethod · 0.80
put_changeMethod · 0.80
update_viewMethod · 0.80
commitMethod · 0.80
get_viewMethod · 0.45
iter_changesMethod · 0.45
get_externalMethod · 0.45
pushMethod · 0.45
create_viewMethod · 0.45