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

Method execute_revise

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

Execute the revise operation.

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

Source from the content-addressed store, hash-verified

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

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