Patchwork D9651: copies-rust: refactor the "deletion" case

login
register
mail settings
Submitter phabricator
Date Dec. 21, 2020, 10:29 p.m.
Message ID <differential-rev-PHID-DREV-37c2bjajic6dlslppnvc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47961/
State New
Headers show

Comments

phabricator - Dec. 21, 2020, 10:29 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9651

AFFECTED FILES
  rust/hg-core/src/copy_tracing.rs

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/copy_tracing.rs b/rust/hg-core/src/copy_tracing.rs
--- a/rust/hg-core/src/copy_tracing.rs
+++ b/rust/hg-core/src/copy_tracing.rs
@@ -515,22 +515,35 @@ 
                 // propagate this information when merging two
                 // InternalPathCopies object.
                 let deleted = path_map.tokenize(deleted_path);
-                match &mut p1_copies {
-                    None => (),
-                    Some(copies) => {
-                        copies.entry(deleted).and_modify(|old| {
-                            old.mark_delete(current_rev);
-                        });
-                    }
+
+                let p1_entry = match &mut p1_copies {
+                    None => None,
+                    Some(copies) => match copies.entry(deleted) {
+                        Entry::Occupied(e) => Some(e),
+                        Entry::Vacant(_) => None,
+                    },
+                };
+                let p2_entry = match &mut p2_copies {
+                    None => None,
+                    Some(copies) => match copies.entry(deleted) {
+                        Entry::Occupied(e) => Some(e),
+                        Entry::Vacant(_) => None,
+                    },
                 };
-                match &mut p2_copies {
-                    None => (),
-                    Some(copies) => {
-                        copies.entry(deleted).and_modify(|old| {
-                            old.mark_delete(current_rev);
-                        });
+
+                match (p1_entry, p2_entry) {
+                    (None, None) => (),
+                    (Some(mut e), None) => {
+                        e.get_mut().mark_delete(current_rev)
                     }
-                };
+                    (None, Some(mut e)) => {
+                        e.get_mut().mark_delete(current_rev)
+                    }
+                    (Some(mut e1), Some(mut e2)) => {
+                        e1.get_mut().mark_delete(current_rev);
+                        e2.get_mut().mark_delete(current_rev);
+                    }
+                }
             }
         }
     }