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

Function run_preview

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

Preview what would be inserted.

(repo: &Repository, args: &PreviewArgs)

Source from the content-addressed store, hash-verified

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