Build the real per-file unified diff for a change by reusing the exact `atomic diff -c ` builder ([`change_file_diffs`]), then converting each `FileDiff` into the serializable [`DiffFileView`] mirror. Best-effort: on any error this returns an empty vec (the report still carries message/files).
(repo: &Repository, change: &Change, hash: &Hash)
| 1036 | /// `FileDiff` into the serializable [`DiffFileView`] mirror. Best-effort: on any |
| 1037 | /// error this returns an empty vec (the report still carries message/files). |
| 1038 | fn build_change_diff(repo: &Repository, change: &Change, hash: &Hash) -> Vec<DiffFileView> { |
| 1039 | // Sensible review defaults: unified, a few context lines, no color/word-diff. |
| 1040 | let config = DiffOutputConfig::new().with_color(false); |
| 1041 | debug_assert_eq!(config.format, DiffFormat::Unified); |
| 1042 | |
| 1043 | let file_diffs = match change_file_diffs(repo, change, hash, &config) { |
| 1044 | Ok((file_diffs, _stats)) => file_diffs, |
| 1045 | Err(_) => return Vec::new(), |
| 1046 | }; |
| 1047 | |
| 1048 | let mut out = Vec::with_capacity(file_diffs.len()); |
| 1049 | for fd in file_diffs { |
| 1050 | let status = match fd.status { |
| 1051 | FileChangeStatus::Added => "added", |
| 1052 | FileChangeStatus::Deleted => "deleted", |
| 1053 | _ => "modified", |
| 1054 | } |
| 1055 | .to_string(); |
| 1056 | let path = if !fd.new_path.is_empty() { |
| 1057 | fd.new_path.clone() |
| 1058 | } else { |
| 1059 | fd.old_path.clone() |
| 1060 | }; |
| 1061 | |
| 1062 | let total_lines: usize = fd.hunks.iter().map(|h| h.lines.len()).sum(); |
| 1063 | let hunks = if total_lines > MAX_DIFF_LINES_PER_FILE { |
| 1064 | // Too large to embed: leave a note pointing at the full command. |
| 1065 | vec![DiffHunkView { |
| 1066 | header: format!("@@ {path} @@"), |
| 1067 | lines: vec![DiffLineView { |
| 1068 | tag: " ".to_string(), |
| 1069 | content: format!( |
| 1070 | "[diff omitted: {total_lines} lines exceed embed cap; run: atomic change {} --show-hunks]", |
| 1071 | hash.to_base32() |
| 1072 | ), |
| 1073 | }], |
| 1074 | }] |
| 1075 | } else { |
| 1076 | fd.hunks |
| 1077 | .iter() |
| 1078 | .map(|h| DiffHunkView { |
| 1079 | header: h.header(), |
| 1080 | lines: h |
| 1081 | .lines |
| 1082 | .iter() |
| 1083 | .map(|l| DiffLineView { |
| 1084 | tag: l.status.prefix().to_string(), |
| 1085 | content: l.content.clone(), |
| 1086 | }) |
| 1087 | .collect(), |
| 1088 | }) |
| 1089 | .collect() |
| 1090 | }; |
| 1091 | |
| 1092 | out.push(DiffFileView { |
| 1093 | path, |
| 1094 | status, |
| 1095 | hunks, |
no test coverage detected