Patchwork [2,of,5,mergedriver] mergestate: add a cached property accessor for the local context

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 30, 2015, 6:34 p.m.
Message ID <637d1c9f4e5bf7024e9e.1448908492@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11675/
State Accepted
Delegated to: Martin von Zweigbergk
Headers show

Comments

Siddharth Agarwal - Nov. 30, 2015, 6:34 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1448906601 28800
#      Mon Nov 30 10:03:21 2015 -0800
# Node ID 637d1c9f4e5bf7024e9e95c5ba5786d1a91eae61
# Parent  6ea95357d149d5e1b243bc57abd629962dfea072
# Available At http://42.netv6.net/sid0-wip/hg/
#              hg pull http://42.netv6.net/sid0-wip/hg/ -r 637d1c9f4e5b
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.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -103,8 +103,9 @@  class mergestate(object):
         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 @@  class mergestate(object):
         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 @@  class mergestate(object):
         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")