Patchwork D9498: copies-rust: make the comparison aware of the revision being current merged

login
register
mail settings
Submitter phabricator
Date Dec. 2, 2020, 4:03 p.m.
Message ID <differential-rev-PHID-DREV-5zk6vcgvrsysvwkqk3i4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47780/
State Superseded
Headers show

Comments

phabricator - Dec. 2, 2020, 4:03 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This make no significant performance change in practice (all ±2%) in practice,
  but it will help us to distinct between some semantically different cases later
  on.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -422,6 +422,7 @@ 
                     // them.
                     Some(copies) => Some(merge_copies_dict(
                         &path_map,
+                        rev,
                         vertex_copies,
                         copies,
                         &changes,
@@ -549,6 +550,7 @@ 
 /// cases. See inline documentation for details.
 fn merge_copies_dict<A: Fn(Revision, Revision) -> bool>(
     path_map: &TwoWayPathMap,
+    current_merge: Revision,
     mut minor: TimeStampedPathCopies,
     mut major: TimeStampedPathCopies,
     changes: &ChangedFiles,
@@ -562,7 +564,13 @@ 
          src_minor: &TimeStampedPathCopy,
          src_major: &TimeStampedPathCopy| {
             compare_value(
-                path_map, changes, oracle, dest, src_minor, src_major,
+                path_map,
+                current_merge,
+                changes,
+                oracle,
+                dest,
+                src_minor,
+                src_major,
             )
         };
     if minor.is_empty() {
@@ -694,13 +702,33 @@ 
 #[allow(clippy::if_same_then_else)]
 fn compare_value<A: Fn(Revision, Revision) -> bool>(
     path_map: &TwoWayPathMap,
+    current_merge: Revision,
     changes: &ChangedFiles,
     oracle: &mut AncestorOracle<A>,
     dest: &PathToken,
     src_minor: &TimeStampedPathCopy,
     src_major: &TimeStampedPathCopy,
 ) -> MergePick {
-    if src_major.path == src_minor.path {
+    if src_major.rev == current_merge {
+        if src_minor.rev == current_merge {
+            if src_major.path.is_none() {
+                // We cannot get different copy information for both p1 and p2
+                // from the same revision. Unless this was a
+                // deletion
+                MergePick::Any
+            } else {
+                unreachable!();
+            }
+        } else {
+            // The last value comes the current merge, this value -will- win
+            // eventually.
+            MergePick::Major
+        }
+    } else if src_minor.rev == current_merge {
+        // The last value comes the current merge, this value -will- win
+        // eventually.
+        MergePick::Minor
+    } else if src_major.path == src_minor.path {
         // we have the same value, but from other source;
         if src_major.rev == src_minor.rev {
             // If the two entry are identical, they are both valid