Process a deleted file: create deletion hunks.
(
input: &FileRecordInput,
options: &RecordingOptions,
)
| 193 | |
| 194 | /// Process a deleted file: create deletion hunks. |
| 195 | fn process_deleted_file( |
| 196 | input: &FileRecordInput, |
| 197 | options: &RecordingOptions, |
| 198 | ) -> Result<FileRecordOutput, String> { |
| 199 | let mut detected = DetectedFile::deleted(&input.path); |
| 200 | detected.inode = input.inode; |
| 201 | detected.position = input.position; |
| 202 | |
| 203 | match record_deleted_file(&detected, options) { |
| 204 | Ok(recorded) => { |
| 205 | let crdt_stats = recorded.crdt_stats(); |
| 206 | let file_stats = FileRecordStats { |
| 207 | hunks_created: recorded.hunk_count(), |
| 208 | edges_modified: 1, |
| 209 | lines_added: crdt_stats.map_or(0, |s| s.lines_added), |
| 210 | lines_deleted: crdt_stats.map_or(0, |s| s.lines_deleted), |
| 211 | lines_modified: crdt_stats.map_or(0, |s| s.lines_modified), |
| 212 | tokens_added: crdt_stats.map_or(0, |s| s.tokens_added), |
| 213 | tokens_deleted: crdt_stats.map_or(0, |s| s.tokens_deleted), |
| 214 | tokens_replaced: crdt_stats.map_or(0, |s| s.tokens_replaced), |
| 215 | ..FileRecordStats::default() |
| 216 | }; |
| 217 | |
| 218 | Ok(FileRecordOutput { |
| 219 | path: input.path.clone(), |
| 220 | kind: FileRecordKind::Deleted, |
| 221 | recorded: Some(recorded), |
| 222 | skipped: false, |
| 223 | stats: file_stats, |
| 224 | }) |
| 225 | } |
| 226 | Err(e) => Err(format!( |
| 227 | "Failed to record deletion of {}: {}", |
| 228 | input.path, e |
| 229 | )), |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /// Process an added directory. |
| 234 | fn process_directory_added(input: &FileRecordInput) -> Result<FileRecordOutput, String> { |
no test coverage detected