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

Function run_view_insert

atomic-cli/src/commands/insert.rs:385–451  ·  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

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

Tested by

no test coverage detected