[Updated] D9590: copies: extract value comparison in the python copy tracing

baymax (Baymax, Your Personal Patch-care Companion) phabricator at mercurial-scm.org
Fri Dec 18 14:07:30 UTC 2020


baymax added a comment.
baymax edited the summary of this revision.
baymax updated this revision to Diff 24394.


  ✅ refresh by Heptapod after a successful CI run (🐙 💚)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D9590?vs=24389&id=24394

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D9590/new/

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

AFFECTED FILES
  mercurial/copies.py

CHANGE DETAILS

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -446,6 +446,12 @@
     return final_copies
 
 
+# constant to decide which side to pick with _merge_copies_dict
+PICK_MINOR = 0
+PICK_MAJOR = 1
+PICK_EITHER = 2
+
+
 def _merge_copies_dict(minor, major, isancestor, changes):
     """merge two copies-mapping together, minor and major
 
@@ -464,36 +470,37 @@
         if other is None:
             minor[dest] = value
         else:
-            new_tt = value[0]
-            other_tt = other[0]
-            if value[1] == other[1]:
-                continue
-            # content from "major" wins, unless it is older
-            # than the branch point or there is a merge
-            if new_tt == other_tt:
+            pick = _compare_values(changes, isancestor, dest, other, value)
+            if pick == PICK_MAJOR:
                 minor[dest] = value
-            elif (
-                changes is not None
-                and value[1] is None
-                and dest in changes.salvaged
-            ):
-                pass
-            elif (
-                changes is not None
-                and other[1] is None
-                and dest in changes.salvaged
-            ):
-                minor[dest] = value
-            elif changes is not None and dest in changes.merged:
-                minor[dest] = value
-            elif not isancestor(new_tt, other_tt):
-                if value[1] is not None:
-                    minor[dest] = value
-                elif isancestor(other_tt, new_tt):
-                    minor[dest] = value
     return minor
 
 
+def _compare_values(changes, isancestor, dest, other, value):
+    """compare two value within a _merge_copies_dict loop iteration"""
+    new_tt = value[0]
+    other_tt = other[0]
+
+    if value[1] == other[1]:
+        return PICK_EITHER
+    # content from "major" wins, unless it is older
+    # than the branch point or there is a merge
+    if new_tt == other_tt:
+        return PICK_MAJOR
+    elif changes is not None and value[1] is None and dest in changes.salvaged:
+        return PICK_MINOR
+    elif changes is not None and other[1] is None and dest in changes.salvaged:
+        return PICK_MAJOR
+    elif changes is not None and dest in changes.merged:
+        return PICK_MAJOR
+    elif not isancestor(new_tt, other_tt):
+        if value[1] is not None:
+            return PICK_MAJOR
+        elif isancestor(other_tt, new_tt):
+            return PICK_MAJOR
+    return PICK_MINOR
+
+
 def _revinfo_getter_extra(repo):
     """return a function that return multiple data given a <rev>"i
 



To: marmoute, #hg-reviewers, pulkit
Cc: pulkit, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20201218/79f78662/attachment-0002.html>


More information about the Mercurial-patches mailing list