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

Function run_view_insert

atomic-cli/src/commands/insert.rs:384–449  ·  view source on GitHub ↗

Insert all changes from another view (the `insert view` subcommand).

(repo: &Repository, args: &ViewArgs)

Source from the content-addressed store, hash-verified

382
383/// Insert all changes from another view (the `insert view` subcommand).
384fn run_view_insert(repo: &Repository, args: &ViewArgs) -> CliResult<()> {
385 let to_view = args
386 .to_view
387 .clone()
388 .unwrap_or_else(|| repo.current_view().to_string());
389 let is_current_view = to_view == repo.current_view();
390
391 output::print_info(&format!(
392 "Inserting changes from '{}' to '{}'...",
393 args.from_view, to_view
394 ));
395
396 let options = CrossViewInsertOptions::new(&args.from_view, &to_view)
397 .with_dependencies(args.deps)
398 .allow_conflicts(args.allow_conflicts)
399 .dry_run(args.dry_run);
400
401 let outcome = repo
402 .insert_from_view(options)
403 .map_err(|e| CliError::Conflict {
404 description: e.to_string(),
405 })?;
406
407 print_cross_view_outcome(&outcome, args.dry_run);
408
409 // Update working copy if we inserted into the current view.
410 // Collect affected file paths from the inserted changes and only
411 // materialize those, avoiding a full rematerialization of the
412 // entire working copy.
413 if is_current_view && !args.dry_run && outcome.changes_applied > 0 {
414 let spinner = output::create_spinner("Materializing files for view...");
415
416 let mut affected_paths = std::collections::HashSet::new();
417 for hash in &outcome.applied_hashes {
418 if let Ok(change) = repo.load_change(hash) {
419 for op in change.hunks() {
420 if let Some(p) = op.path() {
421 affected_paths.insert(p.to_string());
422 }
423 }
424 }
425 }
426
427 let output_result = if affected_paths.is_empty() {
428 // No path info available (e.g. AddRoot-only changes) —
429 // fall back to full materialize.
430 repo.materialize().map_err(|e| {
431 CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e))
432 })?
433 } else {
434 repo.materialize_paths(affected_paths).map_err(|e| {
435 CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e))
436 })?
437 };
438
439 output::finish_success(
440 &spinner,
441 &format!(

Callers 1

runMethod · 0.85

Calls 15

print_infoFunction · 0.85
print_cross_view_outcomeFunction · 0.85
create_spinnerFunction · 0.85
finish_successFunction · 0.85
current_viewMethod · 0.80
allow_conflictsMethod · 0.80
insert_from_viewMethod · 0.80
materializeMethod · 0.80
materialize_pathsMethod · 0.80
cloneMethod · 0.45
dry_runMethod · 0.45
with_dependenciesMethod · 0.45

Tested by

no test coverage detected