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

Method create_view_from

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

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

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