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)
| 1065 | /// `FileDiff` into the serializable [`DiffFileView`] mirror. Best-effort: on any |
| 1066 | /// error this returns an empty vec (the report still carries message/files). |
| 1067 | fn build_change_diff(repo: &Repository, change: &Change, hash: &Hash) -> Vec<DiffFileView> { |
| 1068 | // Sensible review defaults: unified, a few context lines, no color/word-diff. |
| 1069 | let config = DiffOutputConfig::new().with_color(false); |
| 1070 | debug_assert_eq!(config.format, DiffFormat::Unified); |
| 1071 | |
| 1072 | let file_diffs = match change_file_diffs(repo, change, hash, &config) { |
| 1073 | Ok((file_diffs, _stats)) => file_diffs, |
| 1074 | Err(_) => return Vec::new(), |
| 1075 | }; |
| 1076 | |
| 1077 | let mut out = Vec::with_capacity(file_diffs.len()); |
| 1078 | for fd in file_diffs { |
| 1079 | let status = match fd.status { |
| 1080 | FileChangeStatus::Added => "added", |
| 1081 | FileChangeStatus::Deleted => "deleted", |
| 1082 | _ => "modified", |
| 1083 | } |
| 1084 | .to_string(); |
| 1085 | let path = if !fd.new_path.is_empty() { |
| 1086 | fd.new_path.clone() |
| 1087 | } else { |
| 1088 | fd.old_path.clone() |
| 1089 | }; |
| 1090 | |
| 1091 | let total_lines: usize = fd.hunks.iter().map(|h| h.lines.len()).sum(); |
| 1092 | let hunks = if total_lines > MAX_DIFF_LINES_PER_FILE { |
| 1093 | // Too large to embed: leave a note pointing at the full command. |
| 1094 | vec![DiffHunkView { |
| 1095 | header: format!("@@ {path} @@"), |
| 1096 | lines: vec![DiffLineView { |
| 1097 | tag: " ".to_string(), |
| 1098 | content: format!( |
| 1099 | "[diff omitted: {total_lines} lines exceed embed cap; run: atomic change {} --show-hunks]", |
| 1100 | hash.to_base32() |
| 1101 | ), |
| 1102 | }], |
| 1103 | }] |
| 1104 | } else { |
| 1105 | fd.hunks |
| 1106 | .iter() |
| 1107 | .map(|h| DiffHunkView { |
| 1108 | header: h.header(), |
| 1109 | lines: h |
| 1110 | .lines |
| 1111 | .iter() |
| 1112 | .map(|l| DiffLineView { |
| 1113 | tag: l.status.prefix().to_string(), |
| 1114 | content: l.content.clone(), |
| 1115 | }) |
| 1116 | .collect(), |
| 1117 | }) |
| 1118 | .collect() |
| 1119 | }; |
| 1120 | |
| 1121 | out.push(DiffFileView { |
| 1122 | path, |
| 1123 | status, |
| 1124 | hunks, |
no test coverage detected