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

Method execute_revise

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

Execute the revise operation.

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

Source from the content-addressed store, hash-verified

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

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