diff mercurial/copies.py @ 42707:3cffc7bbec26

copies: extract an explicit `computechangesetcopie` method from context Right now, the logic around changeset centric copies data are buried into the "changectx" code. We extract this code in a dedicated method (in the copies module) for clarity. This clarity will help to explicitly compute and caches these data in the future.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 06 Aug 2019 03:17:40 +0200
parents 8c5a36805d5d
children f3bcae1e9e23
line wrap: on
line diff
--- a/mercurial/copies.py	Wed Aug 07 19:18:20 2019 +0530
+++ b/mercurial/copies.py	Tue Aug 06 03:17:40 2019 +0200
@@ -809,3 +809,28 @@
             continue
         if dst in wctx:
             wctx[dst].markcopied(src)
+
+def computechangesetcopies(ctx):
+    """return the copies data for a changeset
+
+    The copies data are returned as a pair of dictionnary (p1copies, p2copies).
+
+    Each dictionnary are in the form: `{newname: oldname}`
+    """
+    p1copies = {}
+    p2copies = {}
+    p1 = ctx.p1()
+    p2 = ctx.p2()
+    narrowmatch = ctx._repo.narrowmatch()
+    for dst in ctx.files():
+        if not narrowmatch(dst) or dst not in ctx:
+            continue
+        copied = ctx[dst].renamed()
+        if not copied:
+            continue
+        src, srcnode = copied
+        if src in p1 and p1[src].filenode() == srcnode:
+            p1copies[dst] = src
+        elif src in p2 and p2[src].filenode() == srcnode:
+            p2copies[dst] = src
+    return p1copies, p2copies