| 9224 | |
| 9225 | impl RenameCollisions { |
| 9226 | fn collect(files: &[ParsedFile]) -> Self { |
| 9227 | let added: HashSet<&str> = files |
| 9228 | .iter() |
| 9229 | .filter(|file| file.operation == FileOperation::Added) |
| 9230 | .map(|file| file.path.as_str()) |
| 9231 | .collect(); |
| 9232 | let deleted: HashSet<&str> = files |
| 9233 | .iter() |
| 9234 | .filter(|file| file.operation == FileOperation::Deleted) |
| 9235 | .map(|file| file.path.as_str()) |
| 9236 | .collect(); |
| 9237 | let renames = files |
| 9238 | .iter() |
| 9239 | .filter(|file| file.operation == FileOperation::Renamed) |
| 9240 | .filter_map(|file| file.old_path.as_deref().map(|old_path| (file, old_path))); |
| 9241 | let onto_deleted: HashMap<String, (Option<Vec<u8>>, Option<u32>)> = renames |
| 9242 | .clone() |
| 9243 | .filter(|(file, _)| deleted.contains(file.path.as_str())) |
| 9244 | .map(|(file, _)| (file.path.clone(), (file.new_content.clone(), file.new_mode))) |
| 9245 | .collect(); |
| 9246 | let reoccupied = renames |
| 9247 | .filter(|(file, old_path)| { |
| 9248 | !onto_deleted.contains_key(&file.path) && added.contains(old_path) |
| 9249 | }) |
| 9250 | .map(|(file, old_path)| (old_path.to_string(), file.old_content.clone())) |
| 9251 | .collect(); |
| 9252 | Self { |
| 9253 | onto_deleted, |
| 9254 | reoccupied, |
| 9255 | } |
| 9256 | } |
| 9257 | |
| 9258 | fn is_empty(&self) -> bool { |
| 9259 | self.onto_deleted.is_empty() && self.reoccupied.is_empty() |