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,
)
| 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 |
no test coverage detected