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

Function run_preview

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

Preview what would be inserted.

(repo: &Repository, args: &PreviewArgs)

Source from the content-addressed store, hash-verified

417
418/// Preview what would be inserted.
419fn run_preview(repo: &Repository, args: &PreviewArgs) -> CliResult<()> {
420 let to_view = args
421 .to_view
422 .clone()
423 .unwrap_or_else(|| repo.current_view().to_string());
424
425 output::print_section("Insert Preview");
426 println!();
427 println!(" Source view: {}", args.from_view);
428 println!(" Target view: {}", to_view);
429 if let Some(ref tag) = args.up_to_tag {
430 println!(" Up to tag: {}", tag);
431 }
432 println!();
433
434 // Get the changes that would be inserted
435 let missing = if let Some(ref tag_name) = args.up_to_tag {
436 // Get changes up to tag, then filter to missing
437 let options = CrossViewInsertOptions::new(&args.from_view, &to_view)
438 .up_to_tag(tag_name)
439 .dry_run(true);
440
441 let outcome = repo
442 .insert_from_view(options)
443 .map_err(|e| CliError::Conflict {
444 description: e.to_string(),
445 })?;
446
447 outcome.applied_hashes
448 } else {
449 repo.get_missing_changes_between(&args.from_view, Some(&to_view))
450 .map_err(|e| CliError::Conflict {
451 description: e.to_string(),
452 })?
453 };
454
455 if missing.is_empty() {
456 output::print_success("No changes to insert - target view is up to date.");
457 } else {
458 println!("Changes that would be inserted ({}):", missing.len());
459 println!();
460 for (i, hash) in missing.iter().enumerate() {
461 // Try to load change header for more info
462 if let Ok(change) = repo.load_change(hash) {
463 let message = &change.hashed.header.message;
464 let short_msg = if message.len() > 50 {
465 format!("{}...", &message[..47])
466 } else {
467 message.to_string()
468 };
469 println!(" {}. {} {}", i + 1, format_hash(hash, true), short_msg);
470 } else {
471 println!(" {}. {}", i + 1, format_hash(hash, true));
472 }
473 }
474 println!();
475 output::print_info(&format!(
476 "Run 'atomic insert from-view {}' to insert these changes.",

Callers 1

runMethod · 0.85

Calls 13

print_sectionFunction · 0.85
print_successFunction · 0.85
print_infoFunction · 0.85
current_viewMethod · 0.80
up_to_tagMethod · 0.80
insert_from_viewMethod · 0.80
cloneMethod · 0.45
dry_runMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45
load_changeMethod · 0.45

Tested by

no test coverage detected