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,
)
| 845 | /// |
| 846 | /// Used when a change doesn't have file_ops (old changes or graph-only changes). |
| 847 | fn show_change_diff_computed( |
| 848 | &self, |
| 849 | repo: &Repository, |
| 850 | change: &Change, |
| 851 | hash: &Hash, |
| 852 | config: &DiffOutputConfig, |
| 853 | ) -> CliResult<()> { |
| 854 | use atomic_repository::get_files_in_change; |
| 855 | |
| 856 | // Get all files modified by this change, honoring the positional |
| 857 | // file filter (`diff --change <hash> <file>`) |
| 858 | let modified_files: Vec<_> = get_files_in_change(change) |
| 859 | .into_iter() |
| 860 | .filter(|path| self.file_matches_filter(path)) |
| 861 | .collect(); |
| 862 | |
| 863 | if modified_files.is_empty() { |
| 864 | self.print_no_changes(); |
| 865 | return Ok(()); |
| 866 | } |
| 867 | |
| 868 | // Parse algorithm for diffing |
| 869 | let algorithm = self.parse_algorithm()?; |
| 870 | |
| 871 | // Compute diffs for each file using state-based content retrieval |
| 872 | let mut file_diffs = Vec::new(); |
| 873 | let mut stats = DiffStats::new(); |
| 874 | |
| 875 | for file_path in &modified_files { |
| 876 | // Get content BEFORE the change was applied |
| 877 | let before_content = match repo.get_file_content_before_change(file_path, hash) { |
| 878 | Ok(content) => content.unwrap_or_default(), |
| 879 | Err(_) => Vec::new(), |
| 880 | }; |
| 881 | |
| 882 | // Get content AFTER the change was applied |
| 883 | let after_content = match repo.get_file_content_after_change(file_path, hash) { |
| 884 | Ok(content) => content.unwrap_or_default(), |
| 885 | Err(_) => Vec::new(), |
| 886 | }; |
| 887 | |
| 888 | // Determine the type of change based on before/after content |
| 889 | let file_diff = match (before_content.is_empty(), after_content.is_empty()) { |
| 890 | // File was added (no content before, has content after) |
| 891 | (true, false) => { |
| 892 | let mut diff = FileDiff::added(file_path); |
| 893 | let lines: Vec<_> = after_content.split(|&b| b == b'\n').collect(); |
| 894 | let line_count = lines.len(); |
| 895 | |
| 896 | if !after_content.is_empty() { |
| 897 | let mut graph_op = DiffHunk::new(0, 0, 1, line_count); |
| 898 | for (i, line_bytes) in lines.iter().enumerate() { |
| 899 | let line_content = String::from_utf8_lossy(line_bytes).into_owned(); |
| 900 | graph_op.add_line(HunkLine::added(line_content, i + 1)); |
| 901 | } |
| 902 | diff.add_hunk(graph_op); |
| 903 | } |
| 904 |
no test coverage detected