| 342 | } |
| 343 | |
| 344 | fn pair_paths( |
| 345 | before: &BTreeMap<String, String>, |
| 346 | after: &BTreeMap<String, String>, |
| 347 | ) -> Vec<(Option<String>, Option<String>)> { |
| 348 | let mut old: BTreeSet<_> = before.keys().cloned().collect(); |
| 349 | let mut new: BTreeSet<_> = after.keys().cloned().collect(); |
| 350 | let mut pairs = Vec::new(); |
| 351 | for path in before |
| 352 | .keys() |
| 353 | .filter(|path| after.get(*path) == before.get(*path)) |
| 354 | { |
| 355 | old.remove(path); |
| 356 | new.remove(path); |
| 357 | pairs.push((Some(path.clone()), Some(path.clone()))); |
| 358 | } |
| 359 | let mut old_ids = BTreeMap::<&str, Vec<String>>::new(); |
| 360 | let mut new_ids = BTreeMap::<&str, Vec<String>>::new(); |
| 361 | for path in &old { |
| 362 | old_ids.entry(&before[path]).or_default().push(path.clone()); |
| 363 | } |
| 364 | for path in &new { |
| 365 | new_ids.entry(&after[path]).or_default().push(path.clone()); |
| 366 | } |
| 367 | for (inode, paths) in old_ids { |
| 368 | if paths.len() == 1 { |
| 369 | if let Some(targets) = new_ids.get(inode).filter(|paths| paths.len() == 1) { |
| 370 | let a = paths[0].clone(); |
| 371 | let b = targets[0].clone(); |
| 372 | old.remove(&a); |
| 373 | new.remove(&b); |
| 374 | pairs.push((Some(a), Some(b))); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | let replacements = old |
| 379 | .iter() |
| 380 | .filter(|path| new.contains(*path)) |
| 381 | .cloned() |
| 382 | .collect::<Vec<_>>(); |
| 383 | for path in replacements { |
| 384 | old.remove(&path); |
| 385 | new.remove(&path); |
| 386 | pairs.push((Some(path.clone()), Some(path))); |
| 387 | } |
| 388 | pairs.extend(old.into_iter().map(|path| (Some(path), None))); |
| 389 | pairs.extend(new.into_iter().map(|path| (None, Some(path)))); |
| 390 | pairs |
| 391 | } |
| 392 | |
| 393 | pub(super) fn verify(repo: &Repository, comparison: &ViewComparison) -> CliResult<()> { |
| 394 | comparison.conformance.verify(repo)?; |