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

Function run_preview

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

Preview what would be inserted.

(repo: &Repository, args: &PreviewArgs)

Source from the content-addressed store, hash-verified

565
566/// Preview what would be inserted.
567fn run_preview(repo: &Repository, args: &PreviewArgs) -> CliResult<()> {
568 let to_view = args
569 .to_view
570 .clone()
571 .unwrap_or_else(|| repo.current_view().to_string());
572
573 output::print_section("Insert Preview");
574 println!();
575 println!(" Source view: {}", args.from_view);
576 println!(" Target view: {}", to_view);
577 if let Some(ref tag) = args.up_to_tag {
578 println!(" Up to tag: {}", tag);
579 }
580 println!();
581
582 // Get the changes that would be inserted
583 let missing = if let Some(ref tag_name) = args.up_to_tag {
584 // Get changes up to tag, then filter to missing
585 let options = CrossViewInsertOptions::new(&args.from_view, &to_view)
586 .up_to_tag(tag_name)
587 .dry_run(true);
588
589 let outcome = repo
590 .insert_from_view(options)
591 .map_err(|e| CliError::Conflict {
592 description: e.to_string(),
593 })?;
594
595 outcome.applied_hashes
596 } else {
597 repo.get_missing_changes_between(&args.from_view, Some(&to_view))
598 .map_err(|e| CliError::Conflict {
599 description: e.to_string(),
600 })?
601 };
602
603 if missing.is_empty() {
604 output::print_success("No changes to insert - target view is up to date.");
605 } else {
606 println!("Changes that would be inserted ({}):", missing.len());
607 println!();
608 for (i, hash) in missing.iter().enumerate() {
609 // Try to load change header for more info
610 if let Ok(change) = repo.load_change(hash) {
611 let message = &change.hashed.header.message;
612 let short_msg = if message.len() > 50 {
613 format!("{}...", &message[..47])
614 } else {
615 message.to_string()
616 };
617 println!(" {}. {} {}", i + 1, format_hash(hash, true), short_msg);
618 } else {
619 println!(" {}. {}", i + 1, format_hash(hash, true));
620 }
621 }
622 println!();
623 output::print_info(&format!(
624 "Run 'atomic insert 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