Patchwork [2,of,7,mergedriver] merge.mergestate: add a way to get the other side of the merge

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 17, 2015, 2:35 a.m.
Message ID <a1d0e62becae8276351a.1445049315@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11158/
State Accepted
Headers show

Comments

Siddharth Agarwal - Oct. 17, 2015, 2:35 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444895347 25200
#      Thu Oct 15 00:49:07 2015 -0700
# Node ID a1d0e62becae8276351a7dd9a76912cb3ea9f905
# Parent  b7d49ea007826ec28354bb67b10f651a5cbbf905
merge.mergestate: add a way to get the other side of the merge

It's surprising there was no API at all for this until now. In any case this
will be needed from custom merge drivers.
Pierre-Yves David - Oct. 18, 2015, 12:44 p.m.
On 10/17/2015 04:35 AM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1444895347 25200
> #      Thu Oct 15 00:49:07 2015 -0700
> # Node ID a1d0e62becae8276351a7dd9a76912cb3ea9f905
> # Parent  b7d49ea007826ec28354bb67b10f651a5cbbf905
> merge.mergestate: add a way to get the other side of the merge
>
> It's surprising there was no API at all for this until now. In any case this
> will be needed from custom merge drivers.
>
> diff --git a/mercurial/merge.py b/mercurial/merge.py
> --- a/mercurial/merge.py
> +++ b/mercurial/merge.py
> @@ -84,6 +84,8 @@ class mergestate(object):
>           self._state = {}
>           self._local = None
>           self._other = None
> +        if 'otherctx' in vars(self):
> +            del self.__dict__['otherctx']

I've turned that into:

     del self.otherctx

because it seemed more simple.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -84,6 +84,8 @@  class mergestate(object):
         self._state = {}
         self._local = None
         self._other = None
+        if 'otherctx' in vars(self):
+            del self.__dict__['otherctx']
         if node:
             self._local = node
             self._other = other
@@ -101,6 +103,8 @@  class mergestate(object):
         self._local = None
         self._other = None
         self._mdstate = 'u'
+        if 'otherctx' in vars(self):
+            del self.__dict__['otherctx']
         records = self._readrecords()
         for rtype, record in records:
             if rtype == 'L':
@@ -233,6 +237,9 @@  class mergestate(object):
     @util.propertycache
     def mergedriver(self):
         return self._repo.ui.config('experimental', 'mergedriver')
+    @util.propertycache
+    def otherctx(self):
+        return self._repo[self._other]
 
     def active(self):
         """Whether mergestate is active.