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

Method show_change_diff_computed

atomic-cli/src/commands/diff/helpers.rs:547–678  ·  view source on GitHub ↗

Show diff by computing from content (legacy fallback). Used when a change doesn't have file_ops (old changes or graph-only changes).

(
        &self,
        repo: &Repository,
        change: &Change,
        hash: &Hash,
        config: &DiffOutputConfig,
    )

Source from the content-addressed store, hash-verified

545 ///
546 /// Used when a change doesn't have file_ops (old changes or graph-only changes).
547 fn show_change_diff_computed(
548 &self,
549 repo: &Repository,
550 change: &Change,
551 hash: &Hash,
552 config: &DiffOutputConfig,
553 ) -> CliResult<()> {
554 use atomic_repository::get_files_in_change;
555
556 // Get all files modified by this change
557 let modified_files = get_files_in_change(change);
558
559 if modified_files.is_empty() {
560 self.print_no_changes();
561 return Ok(());
562 }
563
564 // Parse algorithm for diffing
565 let algorithm = self.parse_algorithm()?;
566
567 // Compute diffs for each file using state-based content retrieval
568 let mut file_diffs = Vec::new();
569 let mut stats = DiffStats::new();
570
571 for file_path in &modified_files {
572 // Get content BEFORE the change was applied
573 let before_content = match repo.get_file_content_before_change(file_path, hash) {
574 Ok(content) => content.unwrap_or_default(),
575 Err(_) => Vec::new(),
576 };
577
578 // Get content AFTER the change was applied
579 let after_content = match repo.get_file_content_after_change(file_path, hash) {
580 Ok(content) => content.unwrap_or_default(),
581 Err(_) => Vec::new(),
582 };
583
584 // Determine the type of change based on before/after content
585 let file_diff = match (before_content.is_empty(), after_content.is_empty()) {
586 // File was added (no content before, has content after)
587 (true, false) => {
588 let mut diff = FileDiff::added(file_path);
589 let lines: Vec<_> = after_content.split(|&b| b == b'\n').collect();
590 let line_count = lines.len();
591
592 if !after_content.is_empty() {
593 let mut graph_op = DiffHunk::new(0, 0, 1, line_count);
594 for (i, line_bytes) in lines.iter().enumerate() {
595 let line_content = String::from_utf8_lossy(line_bytes).into_owned();
596 graph_op.add_line(HunkLine::added(line_content, i + 1));
597 }
598 diff.add_hunk(graph_op);
599 }
600
601 diff.stats = FileDiffStats::added(file_path, line_count);
602 diff
603 }
604

Callers 1

show_change_diffMethod · 0.80

Calls 15

get_files_in_changeFunction · 0.85
addedFunction · 0.85
deletedFunction · 0.85
modifiedFunction · 0.85
diff_textFunction · 0.85
build_hunks_from_diffFunction · 0.85
print_no_changesMethod · 0.80
compute_statsMethod · 0.80
print_change_headerMethod · 0.80
print_unifiedMethod · 0.80

Tested by

no test coverage detected