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

Method create_view_from

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

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

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