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

Method execute_reword

atomic-cli/src/commands/revise.rs:665–740  ·  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

663 /// 2. No risk of capturing unintended working copy changes
664 /// 3. Works correctly even with pending changes to re-apply
665 fn execute_reword(
666 &self,
667 repo: &Repository,
668 original_change: &Change,
669 message: &str,
670 author: Option<atomic_core::change::Author>,
671 pending_changes: &[Hash],
672 ) -> CliResult<Hash> {
673 // Build new header with updated message
674 let mut new_header = original_change.hashed.header.clone();
675 new_header.message = message.to_string();
676
677 // Update author if provided
678 if let Some(new_author) = author {
679 new_header.authors = vec![new_author];
680 }
681
682 // Create new change with same hunks but new header
683 let new_change = Change::with_file_ops(
684 new_header,
685 original_change.hashed.hunks.clone(),
686 original_change.hashed.file_ops.clone(),
687 original_change.contents.clone(),
688 original_change.hashed.dependencies.clone(),
689 );
690
691 // Sign the reworded change with the current identity. Reword bypasses
692 // the record pipeline (it rebuilds the change directly), so it must
693 // sign here — a revised change is signed like any new record.
694 let mut new_change = new_change;
695 if let Ok(store) = IdentityStore::open_default() {
696 let signing_identity = store.get_default().ok().flatten();
697 if let Some(identity) = signing_identity {
698 if let Ok(keypair) = store.load_keypair(&identity.id, None) {
699 let _ = new_change.sign_with(
700 &atomic_canonical::did::did_for_public_key(&identity.public_key),
701 keypair.secret.as_bytes(),
702 chrono::Utc::now().timestamp(),
703 );
704 }
705 }
706 }
707
708 // Save the new change
709 let new_hash = repo.save_change(&new_change).map_err(|e| {
710 CliError::Internal(anyhow::anyhow!("Failed to save reworded change: {}", e))
711 })?;
712
713 // Insert the new change into the view (it replaces the unrecorded one)
714 repo.insert_change(&new_hash, Default::default())
715 .map_err(|e| {
716 CliError::Internal(anyhow::anyhow!("Failed to apply reworded change: {}", e))
717 })?;
718
719 // Re-apply pending changes
720 if !pending_changes.is_empty() {
721 print_hint(&format!("Re-applying {} changes...", pending_changes.len()));
722

Callers 1

execute_reviseMethod · 0.80

Calls 13

did_for_public_keyFunction · 0.85
print_hintFunction · 0.85
print_warningFunction · 0.85
load_keypairMethod · 0.80
sign_withMethod · 0.80
cloneMethod · 0.45
get_defaultMethod · 0.45
as_bytesMethod · 0.45
timestampMethod · 0.45
save_changeMethod · 0.45
insert_changeMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected