The resolver-parameterized core of [`change_file_diffs`]: `before` supplies a file's pre-change content for context padding (a `None` answer pads nothing — zero-context hunks, still at true offsets).
(
change: &Change,
config: &DiffOutputConfig,
before: F,
)
| 1124 | /// supplies a file's pre-change content for context padding (a `None` |
| 1125 | /// answer pads nothing — zero-context hunks, still at true offsets). |
| 1126 | pub(crate) fn change_file_diffs_with<F>( |
| 1127 | change: &Change, |
| 1128 | config: &DiffOutputConfig, |
| 1129 | before: F, |
| 1130 | ) -> CliResult<(Vec<FileDiff>, DiffStats)> |
| 1131 | where |
| 1132 | F: Fn(&str) -> Option<Vec<u8>>, |
| 1133 | { |
| 1134 | // Git-imported changes carry Git's captured +/- lines in unhashed metadata. |
| 1135 | if let Some((file_diffs, stats)) = Diff::build_git_import_file_diffs(change) { |
| 1136 | return Ok((file_diffs, stats)); |
| 1137 | } |
| 1138 | |
| 1139 | let file_ops = change.file_ops(); |
| 1140 | |
| 1141 | let mut file_diffs = Vec::new(); |
| 1142 | let mut stats = DiffStats::new(); |
| 1143 | |
| 1144 | for ops in file_ops { |
| 1145 | let file_path = ops.path(); |
| 1146 | |
| 1147 | let trunk_op = ops.trunk_op(); |
| 1148 | let line_ops = ops.line_ops(); |
| 1149 | if matches!(trunk_op, Some(TrunkOp::ProjectedSpanEdit { .. })) { |
| 1150 | return Err(CliError::InvalidArgument { |
| 1151 | message: "projected span edit requires a span-aware semantic diff".into(), |
| 1152 | }); |
| 1153 | } |
| 1154 | |
| 1155 | // Determine file change status from trunk operation |
| 1156 | let change_status = match trunk_op { |
| 1157 | Some(TrunkOp::Create { .. }) => FileChangeStatus::Added, |
| 1158 | Some(TrunkOp::Delete { .. }) => FileChangeStatus::Deleted, |
| 1159 | Some(TrunkOp::Move { .. }) => FileChangeStatus::Renamed, |
| 1160 | Some(TrunkOp::Undelete { .. }) |
| 1161 | | Some(TrunkOp::SetMode { .. }) |
| 1162 | | Some(TrunkOp::SetKind { .. }) |
| 1163 | | Some(TrunkOp::ProjectedSpanEdit { .. }) => FileChangeStatus::Modified, |
| 1164 | None => FileChangeStatus::Modified, |
| 1165 | }; |
| 1166 | |
| 1167 | let mut file_diff = match change_status { |
| 1168 | FileChangeStatus::Added => FileDiff::added(file_path), |
| 1169 | FileChangeStatus::Deleted => FileDiff::deleted(file_path), |
| 1170 | FileChangeStatus::Renamed => FileDiff::modified(file_path), |
| 1171 | _ => FileDiff::modified(file_path), |
| 1172 | }; |
| 1173 | |
| 1174 | // A whole-file rewrite's tombstones carry identities, not old text. |
| 1175 | // Render its textual delta using recorded before-content, even when |
| 1176 | // context is disabled or only statistics were requested. |
| 1177 | if let Some((before_content, after_content)) = |
| 1178 | atomic_repository::diff_engine::whole_file_replacement_text( |
| 1179 | ops, |
| 1180 | &change.contents, |
| 1181 | || before(file_path), |
| 1182 | ) |
| 1183 | { |
no test coverage detected