changeset 46648:eca88f5fbcb2

copies: extract function _backwardcopies() for reversing renames I'll add another callers in the next patch. Differential Revision: https://phab.mercurial-scm.org/D10118
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 05 Mar 2021 14:26:52 -0800
parents 86ee73018e62
children 324ded1aa2ab
files mercurial/copies.py
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/copies.py	Fri Mar 05 10:16:44 2021 -0800
+++ b/mercurial/copies.py	Fri Mar 05 14:26:52 2021 -0800
@@ -704,22 +704,28 @@
 
 
 def _backwardrenames(a, b, match):
+    """find renames from a to b"""
     if a._repo.ui.config(b'experimental', b'copytrace') == b'off':
         return {}
 
+    # We don't want to pass in "match" here, since that would filter
+    # the destination by it. Since we're reversing the copies, we want
+    # to filter the source instead.
+    copies = _forwardcopies(b, a)
+    return _reverse_renames(copies, a, match)
+
+
+def _reverse_renames(copies, dst, match):
+    """given copies to context 'dst', finds renames from that context"""
     # Even though we're not taking copies into account, 1:n rename situations
     # can still exist (e.g. hg cp a b; hg mv a c). In those cases we
     # arbitrarily pick one of the renames.
-    # We don't want to pass in "match" here, since that would filter
-    # the destination by it. Since we're reversing the copies, we want
-    # to filter the source instead.
-    f = _forwardcopies(b, a)
     r = {}
-    for k, v in sorted(pycompat.iteritems(f)):
+    for k, v in sorted(pycompat.iteritems(copies)):
         if match and not match(v):
             continue
         # remove copies
-        if v in a:
+        if v in dst:
             continue
         r[v] = k
     return r