Patchwork D6219: memctx: make p[12]copies() correct

login
register
mail settings
Submitter phabricator
Date April 8, 2019, 4:09 p.m.
Message ID <differential-rev-PHID-DREV-ppk6jcse7bcvchox5rt6-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/39536/
State New
Headers show

Comments

phabricator - April 8, 2019, 4:09 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  TODO: extract the code that's duplicated from changectx

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - April 8, 2019, 4:09 p.m.
martinvonz planned changes to this revision.
martinvonz added a subscriber: pulkit.
martinvonz added a comment.


  Not for review, sharing for @pulkit

REPOSITORY
  rHG Mercurial

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

To: martinvonz, #hg-reviewers
Cc: pulkit, mercurial-devel

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -2386,6 +2386,30 @@ 
 
         return scmutil.status(modified, added, removed, [], [], [], [])
 
+    @propertycache
+    def _copies(self):
+        p1copies = {}
+        p2copies = {}
+        p1 = self.p1()
+        p2 = self.p2()
+        narrowmatch = self._repo.narrowmatch()
+        for dst in self.files():
+            if not narrowmatch(dst) or dst not in self:
+                continue
+            copied = self[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
+    def p1copies(self):
+        return self._copies[0]
+    def p2copies(self):
+        return self._copies[1]
+
 class memfilectx(committablefilectx):
     """memfilectx represents an in-memory file to commit.