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

Method split_view

atomic-repository/src/repository/split.rs:263–483  ·  view source on GitHub ↗

Split a set of changes out of a view into a new Draft view. This is a pure metadata operation guarded by a reverse-dependency check: a change cannot leave the source while another change that stays behind still depends on it, unless `cascade` moves the dependents too. See [`SplitOptions`] for the options and [`SplitOutcome`] for the result. # Errors - [`RepositoryError::ViewAlreadyExists`] if `

(
        &mut self,
        working_copy: WorkingCopyId,
        options: SplitOptions,
    )

Source from the content-addressed store, hash-verified

261 /// - [`RepositoryError::ViewSplitHasDependents`] if changes remaining in the
262 /// source depend on the split-out set and `cascade` is not set.
263 pub fn split_view(
264 &mut self,
265 working_copy: WorkingCopyId,
266 options: SplitOptions,
267 ) -> Result<SplitOutcome, RepositoryError> {
268 self.validate_working_copy(working_copy)?;
269 let desired_view = self.desired_view_name(working_copy)?;
270 let db = |e: PristineError| RepositoryError::Database(e.to_string());
271
272 let from_view_name = options
273 .from_view
274 .clone()
275 .unwrap_or_else(|| desired_view.clone());
276
277 if options.changes.is_empty() {
278 return Err(RepositoryError::InvalidOperation {
279 message: "no changes specified to split".to_string(),
280 });
281 }
282
283 // ── Dry run: analyze against a read transaction, mutate nothing. ──
284 if options.dry_run {
285 let txn = self.pristine.read_txn().map_err(db)?;
286 let source = txn.get_view(&from_view_name).map_err(db)?.ok_or_else(|| {
287 RepositoryError::ViewNotFound {
288 name: from_view_name.clone(),
289 }
290 })?;
291
292 if txn.get_view(&options.target_view).map_err(db)?.is_some() {
293 return Err(RepositoryError::ViewAlreadyExists {
294 name: options.target_view.clone(),
295 });
296 }
297
298 let analysis = analyze_split(&txn, &source, &options.changes)?;
299 let blocked = !analysis.dependents.is_empty() && !options.cascade;
300 let moved = if blocked {
301 Vec::new()
302 } else {
303 analysis.closure.clone()
304 };
305 let target_change_count = moved.len() as u64;
306 let source_change_count = source.change_count.saturating_sub(moved.len() as u64);
307
308 return Ok(SplitOutcome {
309 target_view: options.target_view,
310 from_view: from_view_name,
311 was_dry_run: true,
312 blocked,
313 requested: analysis.requested,
314 dependents: analysis.dependents,
315 moved,
316 source_change_count,
317 target_change_count,
318 working_copy_updated: false,
319 files_written: 0,
320 files_removed: 0,

Calls 15

analyze_splitFunction · 0.85
ensure_workspace_dirFunction · 0.85
remove_empty_ancestorsFunction · 0.85
validate_working_copyMethod · 0.80
desired_view_nameMethod · 0.80
read_txnMethod · 0.80
write_txnMethod · 0.80
put_changeMethod · 0.80
del_changeMethod · 0.80
update_viewMethod · 0.80
visible_file_pathsMethod · 0.80
cloneMethod · 0.45