comparison rust/hg-core/src/copy_tracing.rs @ 46580:2076df13d00f

copies-rust: refactor the "deletion" case We rearrange the code to single out the case where information need to be overwritten on both side of the merge. This open the way to better dealing with this case. Differential Revision: https://phab.mercurial-scm.org/D9651
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 16 Dec 2020 10:59:00 +0100
parents 600f8d510ab6
children d6d57bfc1a1b
comparison
equal deleted inserted replaced
46579:600f8d510ab6 46580:2076df13d00f
508 // 508 //
509 // We need to explicitly record them as dropped to 509 // We need to explicitly record them as dropped to
510 // propagate this information when merging two 510 // propagate this information when merging two
511 // InternalPathCopies object. 511 // InternalPathCopies object.
512 let deleted = path_map.tokenize(deleted_path); 512 let deleted = path_map.tokenize(deleted_path);
513 match &mut p1_copies { 513
514 None => (), 514 let p1_entry = match &mut p1_copies {
515 Some(copies) => { 515 None => None,
516 copies.entry(deleted).and_modify(|old| { 516 Some(copies) => match copies.entry(deleted) {
517 old.mark_delete(current_rev); 517 Entry::Occupied(e) => Some(e),
518 }); 518 Entry::Vacant(_) => None,
519 },
520 };
521 let p2_entry = match &mut p2_copies {
522 None => None,
523 Some(copies) => match copies.entry(deleted) {
524 Entry::Occupied(e) => Some(e),
525 Entry::Vacant(_) => None,
526 },
527 };
528
529 match (p1_entry, p2_entry) {
530 (None, None) => (),
531 (Some(mut e), None) => {
532 e.get_mut().mark_delete(current_rev)
519 } 533 }
520 }; 534 (None, Some(mut e)) => {
521 match &mut p2_copies { 535 e.get_mut().mark_delete(current_rev)
522 None => (),
523 Some(copies) => {
524 copies.entry(deleted).and_modify(|old| {
525 old.mark_delete(current_rev);
526 });
527 } 536 }
528 }; 537 (Some(mut e1), Some(mut e2)) => {
538 e1.get_mut().mark_delete(current_rev);
539 e2.get_mut().mark_delete(current_rev);
540 }
541 }
529 } 542 }
530 } 543 }
531 } 544 }
532 (p1_copies, p2_copies) 545 (p1_copies, p2_copies)
533 } 546 }