[PATCH 2 of 2 v2] copies: clean up _related logic

Gábor Stefanik gabor.stefanik at nng.com
Thu Apr 5 11:57:42 EDT 2018


# HG changeset patch
# User Gábor Stefanik <gabor.stefanik at nng.com>
# Date 1522943470 -7200
#      Thu Apr 05 17:51:10 2018 +0200
# Node ID 9f344b1ec04c43870c4ea439451714dbf9b35739
# Parent  7d13af1b5cd6e5c95dceefc7d905429889583c8c
copies: clean up _related logic

The limit parameter was never actually used, since the only way the 4th case
could be reached was if f1r and f2r converged. The new code makes this clear,
and additionally reduces the conditional block to just 3 cases.

diff -r 7d13af1b5cd6 -r 9f344b1ec04c mercurial/copies.py
--- a/mercurial/copies.py       Thu Apr 05 17:52:31 2018 +0200
+++ b/mercurial/copies.py       Thu Apr 05 17:51:10 2018 +0200
@@ -723,7 +723,7 @@

             for candidate in movecandidates:
                 f1 = c1.filectx(candidate)
-                if _related(f1, f2, anc.rev()):
+                if _related(f1, f2):
                     # if there are a few related copies then we'll merge
                     # changes into all of them. This matches the behaviour
                     # of upstream copytracing
@@ -737,7 +737,7 @@
     except StopIteration:
         raise

-def _related(f1, f2, limit):
+def _related(f1, f2):
     """return True if f1 and f2 filectx have a common ancestor

     Walk back to common ancestor to see if the two files originate
@@ -764,10 +764,8 @@
                 f1, g1 = _loosenext(g1)
             elif f2r > f1r:
                 f2, g2 = _loosenext(g2)
-            elif f1 == f2:
-                return f1 # a match
-            elif f1r == f2r or f1r < limit or f2r < limit:
-                return False # copy no longer relevant
+            else: # f1 and f2 point to files in the same linkrev
+                return f1 == f2 # true if they point to the same file
     except StopIteration:
         return False

@@ -835,7 +833,7 @@
         c2 = getdstfctx(of, mdst[of])
         # c2 might be a plain new file on added on destination side that is
         # unrelated to the droids we are looking for.
-        cr = _related(oc, c2, tca.rev())
+        cr = _related(oc, c2)
         if cr and (of == f or of == c2.path()): # non-divergent
             if backwards:
                 data['copy'][of] = f
________________________________
 This message, including its attachments, is confidential and the property of NNG Llc. For more information please read NNG's email policy here:
https://www.nng.com/email-policy/
By responding to this email you accept the email policy.


More information about the Mercurial-devel mailing list