changeset 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
files rust/hg-core/src/copy_tracing.rs
diffstat 1 files changed, 27 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/copy_tracing.rs	Wed Dec 16 10:46:08 2020 +0100
+++ b/rust/hg-core/src/copy_tracing.rs	Wed Dec 16 10:59:00 2020 +0100
@@ -510,22 +510,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);
+                    }
+                }
             }
         }
     }