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

Method create_view_from

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

326 /// repo.create_view_from("feature", "dev")?;
327 /// ```
328 pub fn create_view_from(&mut self, name: &str, from_view: &str) -> Result<(), RepositoryError> {
329 let mut txn = self
330 .pristine
331 .write_txn()
332 .map_err(|e| RepositoryError::Database(e.to_string()))?;
333
334 // Check if the new view already exists
335 if txn
336 .get_view(name)
337 .map_err(|e| RepositoryError::Database(e.to_string()))?
338 .is_some()
339 {
340 return Err(RepositoryError::ViewAlreadyExists {
341 name: name.to_string(),
342 });
343 }
344
345 // Get the source view
346 let source_view = txn
347 .get_view(from_view)
348 .map_err(|e| RepositoryError::Database(e.to_string()))?
349 .ok_or_else(|| RepositoryError::ViewNotFound {
350 name: from_view.to_string(),
351 })?;
352
353 let source_id = source_view.id;
354
355 // Collect all changes from the source view
356 let changes: Vec<(NodeId, Hash)> = {
357 let iter = txn
358 .iter_changes(&source_view, 0)
359 .map_err(|e| RepositoryError::Database(e.to_string()))?;
360
361 let mut result = Vec::new();
362 for item in iter {
363 let (_seq, node_id, _merkle) =
364 item.map_err(|e| RepositoryError::Database(e.to_string()))?;
365 let hash = txn
366 .get_external(node_id)
367 .map_err(|e| RepositoryError::Database(e.to_string()))?
368 .ok_or_else(|| {
369 RepositoryError::Database(format!(
370 "Change {} has no external hash",
371 node_id.0
372 ))
373 })?;
374 result.push((node_id, hash));
375 }
376 result
377 };
378
379 // Create the new view as a **Draft** view parented on the
380 // source view. Draft views write edges to GRAPH like all
381 // views, but use a change filter for isolation. The parent
382 // link means the view chain includes the source's content.
383 // Create workspace directory for the new view.
384 ensure_workspace_dir(&self.dot_dir, name)?;
385

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