mergestate: add a cached property accessor for the local context
authorSiddharth Agarwal <sid0@fb.com>
Mon, 30 Nov 2015 10:03:21 -0800
changeset 27130 6f045b563fa5
parent 27129 1bf1a7c3df43
child 27131 d837da26155e
mergestate: add a cached property accessor for the local context This is going to be useful in an upcoming patch. We make this a public accessor because this is also going to be useful for custom merge drivers.
mercurial/merge.py
--- a/mercurial/merge.py	Mon Nov 30 10:05:09 2015 -0800
+++ b/mercurial/merge.py	Mon Nov 30 10:03:21 2015 -0800
@@ -103,8 +103,9 @@
         self._state = {}
         self._local = None
         self._other = None
-        if 'otherctx' in vars(self):
-            del self.otherctx
+        for var in ('localctx', 'otherctx'):
+            if var in vars(self):
+                delattr(self, var)
         if node:
             self._local = node
             self._other = other
@@ -126,8 +127,9 @@
         self._state = {}
         self._local = None
         self._other = None
-        if 'otherctx' in vars(self):
-            del self.otherctx
+        for var in ('localctx', 'otherctx'):
+            if var in vars(self):
+                delattr(self, var)
         self._readmergedriver = None
         self._mdstate = 's'
         unsupported = set()
@@ -287,6 +289,12 @@
         return configmergedriver
 
     @util.propertycache
+    def localctx(self):
+        if self._local is None:
+            raise RuntimeError("localctx accessed but self._local isn't set")
+        return self._repo[self._local]
+
+    @util.propertycache
     def otherctx(self):
         if self._other is None:
             raise RuntimeError("localctx accessed but self._local isn't set")