changeset 33804:1f8460b55986

sshpeer: use peer interface We need the same @property conversion of ui like we did for localpeer. We renamed _capabilities() to capabilities() to satisfy the new naming requirement. However, since we're inheriting from wireproto.wirepeer which inherits from peer.peerrepository and provides its own code accessing _capabilities(), we need to keep the old alias around. This wonkiness will disappear once wirepeer is cleaned up in subsequent commits. We also implement methods for basepeer that are identical to the defaults in peer.peerrepository in preparation for the removal of peerrepository. Differential Revision: https://phab.mercurial-scm.org/D336
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 06 Aug 2017 17:59:48 -0700
parents 707750e5310b
children f913e90f15a0
files mercurial/sshpeer.py
diffstat 1 files changed, 33 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/sshpeer.py	Wed Aug 09 23:52:25 2017 -0700
+++ b/mercurial/sshpeer.py	Sun Aug 06 17:59:48 2017 -0700
@@ -13,6 +13,7 @@
 from . import (
     error,
     pycompat,
+    repository,
     util,
     wireproto,
 )
@@ -114,10 +115,10 @@
     def flush(self):
         return self._main.flush()
 
-class sshpeer(wireproto.wirepeer):
+class sshpeer(wireproto.wirepeer, repository.legacypeer):
     def __init__(self, ui, path, create=False):
         self._url = path
-        self.ui = ui
+        self._ui = ui
         self._pipeo = self._pipei = self._pipee = None
 
         u = util.url(path, parsequery=False, parsefragment=False)
@@ -150,9 +151,39 @@
 
         self._validaterepo(sshcmd, args, remotecmd)
 
+        # TODO remove this alias once peerrepository inheritance is removed.
+        self._capabilities = self.capabilities
+
+    # Begin of _basepeer interface.
+
+    @util.propertycache
+    def ui(self):
+        return self._ui
+
     def url(self):
         return self._url
 
+    def local(self):
+        return None
+
+    def peer(self):
+        return self
+
+    def canpush(self):
+        return True
+
+    def close(self):
+        pass
+
+    # End of _basepeer interface.
+
+    # Begin of _basewirecommands interface.
+
+    def capabilities(self):
+        return self._caps
+
+    # End of _basewirecommands interface.
+
     def _validaterepo(self, sshcmd, args, remotecmd):
         # cleanup up previous run
         self._cleanup()
@@ -200,9 +231,6 @@
                 self._caps.update(l[:-1].split(":")[1].split())
                 break
 
-    def _capabilities(self):
-        return self._caps
-
     def _readerr(self):
         _forwardoutput(self.ui, self._pipee)