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

Method execute_reword

atomic-cli/src/commands/revise.rs:664–722  ·  view source on GitHub ↗

Execute reword operation - creates new change with same content but new header. This is cleaner than going through working copy because: 1. We preserve exact same hunks/content 2. No risk of capturing unintended working copy changes 3. Works correctly even with pending changes to re-apply

(
        &self,
        repo: &Repository,
        original_change: &Change,
        message: &str,
        author: Option<atomic_core::change::Author>,
        pending_changes: &[Hash],
    )

Source from the content-addressed store, hash-verified

662 /// 2. No risk of capturing unintended working copy changes
663 /// 3. Works correctly even with pending changes to re-apply
664 fn execute_reword(
665 &self,
666 repo: &Repository,
667 original_change: &Change,
668 message: &str,
669 author: Option<atomic_core::change::Author>,
670 pending_changes: &[Hash],
671 ) -> CliResult<Hash> {
672 // Build new header with updated message
673 let mut new_header = original_change.hashed.header.clone();
674 new_header.message = message.to_string();
675
676 // Update author if provided
677 if let Some(new_author) = author {
678 new_header.authors = vec![new_author];
679 }
680
681 // Create new change with same hunks but new header
682 let new_change = Change::with_file_ops(
683 new_header,
684 original_change.hashed.hunks.clone(),
685 original_change.hashed.file_ops.clone(),
686 original_change.contents.clone(),
687 original_change.hashed.dependencies.clone(),
688 );
689
690 // Save the new change
691 let new_hash = repo.save_change(&new_change).map_err(|e| {
692 CliError::Internal(anyhow::anyhow!("Failed to save reworded change: {}", e))
693 })?;
694
695 // Insert the new change into the view (it replaces the unrecorded one)
696 repo.insert_change(&new_hash, Default::default())
697 .map_err(|e| {
698 CliError::Internal(anyhow::anyhow!("Failed to apply reworded change: {}", e))
699 })?;
700
701 // Re-apply pending changes
702 if !pending_changes.is_empty() {
703 print_hint(&format!("Re-applying {} changes...", pending_changes.len()));
704
705 for hash in pending_changes {
706 repo.reinsert_change(hash, None).map_err(|e| {
707 print_warning(&format!(
708 "Failed to re-apply change {}: {}",
709 format_hash(hash, false),
710 e
711 ));
712 CliError::Internal(anyhow::anyhow!(
713 "Failed to re-apply change {}: {}",
714 format_hash(hash, false),
715 e
716 ))
717 })?;
718 }
719 }
720
721 Ok(new_hash)

Callers 1

execute_reviseMethod · 0.80

Calls 7

print_hintFunction · 0.85
print_warningFunction · 0.85
cloneMethod · 0.45
save_changeMethod · 0.45
insert_changeMethod · 0.45
is_emptyMethod · 0.45
reinsert_changeMethod · 0.45

Tested by

no test coverage detected