context: add specialized way of getting copy source file only
authorMartin von Zweigbergk <martinvonz@google.com>
Sun, 25 Mar 2018 21:32:16 -0700
changeset 41768 041d829575ed
parent 41767 1c1c4ef8b72e
child 41769 e9413a3be093
context: add specialized way of getting copy source file only I'm working on support for storing copy metadata in the changeset instead of the filelog. I don't intend to include the file nodeid there, but most callers don't need that anyway. This patch introduces a method similar to ctx.renamed(), but the new method returns only the source filename, not the nodeid. Subsequent patches will move callers over to this new method. Differential Revision: https://phab.mercurial-scm.org/D6008
hgext/remotefilelog/remotefilectx.py
mercurial/context.py
--- a/hgext/remotefilelog/remotefilectx.py	Thu Feb 21 21:27:42 2019 -0800
+++ b/hgext/remotefilelog/remotefilectx.py	Sun Mar 25 21:32:16 2018 -0700
@@ -136,6 +136,10 @@
                 pass
         return renamed
 
+    def copysource(self):
+        copy = self.renamed()
+        return copy and copy[0]
+
     def ancestormap(self):
         if not self._ancestormap:
             self._ancestormap = self.filelog().ancestormap(self._filenode)
--- a/mercurial/context.py	Thu Feb 21 21:27:42 2019 -0800
+++ b/mercurial/context.py	Sun Mar 25 21:32:16 2018 -0700
@@ -691,6 +691,8 @@
         return self._changectx
     def renamed(self):
         return self._copied
+    def copysource(self):
+        return self._copied and self._copied[0]
     def repo(self):
         return self._repo
     def size(self):
@@ -1703,6 +1705,8 @@
         if not rp:
             return None
         return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
+    def copysource(self):
+        return self._repo.dirstate.copied(self._path)
 
     def size(self):
         return self._repo.wvfs.lstat(self._path).st_size
@@ -2148,6 +2152,9 @@
             return None
         return path, self._changectx._parents[0]._manifest.get(path, nullid)
 
+    def copysource(self):
+        return self._parent.copydata(self._path)
+
     def size(self):
         return self._parent.size(self._path)