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,
)
| 633 | /// |
| 634 | /// Used when a change doesn't have file_ops (old changes or graph-only changes). |
| 635 | fn show_change_diff_computed( |
| 636 | &self, |
| 637 | repo: &Repository, |
| 638 | change: &Change, |
| 639 | hash: &Hash, |
| 640 | config: &DiffOutputConfig, |
| 641 | ) -> CliResult<()> { |
| 642 | use atomic_repository::get_files_in_change; |
| 643 | |
| 644 | // Get all files modified by this change, honoring the positional |
| 645 | // file filter (`diff --change <hash> <file>`) |
| 646 | let modified_files: Vec<_> = get_files_in_change(change) |
| 647 | .into_iter() |
| 648 | .filter(|path| self.file_matches_filter(path)) |
| 649 | .collect(); |
| 650 | |
| 651 | if modified_files.is_empty() { |
| 652 | self.print_no_changes(); |
| 653 | return Ok(()); |
| 654 | } |
| 655 | |
| 656 | // Parse algorithm for diffing |
| 657 | let algorithm = self.parse_algorithm()?; |
| 658 | |
| 659 | // Compute diffs for each file using state-based content retrieval |
| 660 | let mut file_diffs = Vec::new(); |
| 661 | let mut stats = DiffStats::new(); |
| 662 | |
| 663 | for file_path in &modified_files { |
| 664 | // Get content BEFORE the change was applied |
| 665 | let before_content = match repo.get_file_content_before_change(file_path, hash) { |
| 666 | Ok(content) => content.unwrap_or_default(), |
| 667 | Err(_) => Vec::new(), |
| 668 | }; |
| 669 | |
| 670 | // Get content AFTER the change was applied |
| 671 | let after_content = match repo.get_file_content_after_change(file_path, hash) { |
| 672 | Ok(content) => content.unwrap_or_default(), |
| 673 | Err(_) => Vec::new(), |
| 674 | }; |
| 675 | |
| 676 | // Determine the type of change based on before/after content |
| 677 | let file_diff = match (before_content.is_empty(), after_content.is_empty()) { |
| 678 | // File was added (no content before, has content after) |
| 679 | (true, false) => { |
| 680 | let mut diff = FileDiff::added(file_path); |
| 681 | let lines: Vec<_> = after_content.split(|&b| b == b'\n').collect(); |
| 682 | let line_count = lines.len(); |
| 683 | |
| 684 | if !after_content.is_empty() { |
| 685 | let mut graph_op = DiffHunk::new(0, 0, 1, line_count); |
| 686 | for (i, line_bytes) in lines.iter().enumerate() { |
| 687 | let line_content = String::from_utf8_lossy(line_bytes).into_owned(); |
| 688 | graph_op.add_line(HunkLine::added(line_content, i + 1)); |
| 689 | } |
| 690 | diff.add_hunk(graph_op); |
| 691 | } |
| 692 |
no test coverage detected