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,
)
| 776 | /// |
| 777 | /// Used when a change doesn't have file_ops (old changes or graph-only changes). |
| 778 | fn show_change_diff_computed( |
| 779 | &self, |
| 780 | repo: &Repository, |
| 781 | change: &Change, |
| 782 | hash: &Hash, |
| 783 | config: &DiffOutputConfig, |
| 784 | ) -> CliResult<()> { |
| 785 | use atomic_repository::get_files_in_change; |
| 786 | |
| 787 | // Get all files modified by this change, honoring the positional |
| 788 | // file filter (`diff --change <hash> <file>`) |
| 789 | let modified_files: Vec<_> = get_files_in_change(change) |
| 790 | .into_iter() |
| 791 | .filter(|path| self.file_matches_filter(path)) |
| 792 | .collect(); |
| 793 | |
| 794 | if modified_files.is_empty() { |
| 795 | self.print_no_changes(); |
| 796 | return Ok(()); |
| 797 | } |
| 798 | |
| 799 | // Parse algorithm for diffing |
| 800 | let algorithm = self.parse_algorithm()?; |
| 801 | |
| 802 | // Compute the per-file before/after content from the graph, then |
| 803 | // build the diffs with the SAME builder the routed path runs over |
| 804 | // wire-carried content (one computation, two data sources). |
| 805 | let mut entries = Vec::with_capacity(modified_files.len()); |
| 806 | for file_path in &modified_files { |
| 807 | let before_content = match repo.get_file_content_before_change(file_path, hash) { |
| 808 | Ok(content) => content.unwrap_or_default(), |
| 809 | Err(_) => Vec::new(), |
| 810 | }; |
| 811 | let after_content = match repo.get_file_content_after_change(file_path, hash) { |
| 812 | Ok(content) => content.unwrap_or_default(), |
| 813 | Err(_) => Vec::new(), |
| 814 | }; |
| 815 | entries.push((file_path.clone(), before_content, after_content)); |
| 816 | } |
| 817 | let (file_diffs, stats) = |
| 818 | legacy_content_file_diffs(&entries, algorithm, config.context_lines); |
| 819 | |
| 820 | if file_diffs.is_empty() { |
| 821 | self.print_no_changes(); |
| 822 | return Ok(()); |
| 823 | } |
| 824 | |
| 825 | // Print change header information |
| 826 | if !self.json && config.format == DiffFormat::Unified { |
| 827 | self.print_change_header(change, hash, config); |
| 828 | } |
| 829 | |
| 830 | // Print in the appropriate format |
| 831 | self.render(&file_diffs, &stats, config, Some((change, hash)), None) |
| 832 | } |
| 833 | |
| 834 | /// Print header information for a change diff. |
| 835 | /// |
no test coverage detected