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:542–673  ·  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

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

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