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

Method create_view_from

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

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

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