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

Method execute_revise

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

Execute the revise operation.

(
        &self,
        repo: &Repository,
        sequence: u64,
        entry: &HistoryEntry,
    )

Source from the content-addressed store, hash-verified

514
515 /// Execute the revise operation.
516 fn execute_revise(
517 &self,
518 repo: &Repository,
519 sequence: u64,
520 entry: &HistoryEntry,
521 ) -> CliResult<Hash> {
522 let stack_name = repo.current_view();
523 let stack_info = repo
524 .get_view_info(stack_name)
525 .map_err(CliError::Repository)?;
526
527 // Load the original change to get its message
528 let original_change = repo
529 .load_change(&entry.hash)
530 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load change: {}", e)))?;
531
532 let original_message = original_change.hashed.header.message.clone();
533
534 // Determine how many changes need to be unrecorded
535 let changes_to_unrecord = stack_info.change_count - sequence;
536
537 // Collect changes that will need to be re-applied (everything after target)
538 let mut pending_changes: Vec<Hash> = Vec::new();
539
540 if changes_to_unrecord > 1 {
541 // Get history and collect changes after the target
542 let history = repo
543 .log(HistoryOptions::default())
544 .map_err(CliError::Repository)?;
545
546 // Collect entries after the target sequence, sorted by sequence
547 let mut entries_after: Vec<_> = history
548 .into_iter()
549 .filter(|e| e.sequence > sequence)
550 .collect();
551 entries_after.sort_by_key(|e| e.sequence);
552
553 // Extract hashes in order (oldest first for re-application)
554 pending_changes = entries_after.into_iter().map(|e| e.hash).collect();
555 }
556
557 // Step 1: Unrecord changes from top down to (and including) target
558 if !pending_changes.is_empty() {
559 print_hint(&format!(
560 "Temporarily unrecording {} changes after target...",
561 pending_changes.len()
562 ));
563 }
564
565 // Unrecord in reverse order (from newest to target)
566 for _ in 0..changes_to_unrecord {
567 repo.unrecord_last(UnrecordOptions::default())
568 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to unrecord: {}", e)))?;
569 }
570
571 // Step 2: Get the message for the new change
572 let message = self.get_message(&original_message)?;
573

Callers 1

runMethod · 0.80

Calls 15

print_hintFunction · 0.85
print_warningFunction · 0.85
current_viewMethod · 0.80
get_view_infoMethod · 0.80
logMethod · 0.80
unrecord_lastMethod · 0.80
execute_rewordMethod · 0.80
authorMethod · 0.80
load_changeMethod · 0.45
cloneMethod · 0.45
into_iterMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected