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.
--- 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")