Mercurial > public > mercurial-scm > hg
comparison mercurial/sshpeer.py @ 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 | 82d564d5ac4f |
children | dedab036215d |
comparison
equal
deleted
inserted
replaced
33803:707750e5310b | 33804:1f8460b55986 |
---|---|
11 | 11 |
12 from .i18n import _ | 12 from .i18n import _ |
13 from . import ( | 13 from . import ( |
14 error, | 14 error, |
15 pycompat, | 15 pycompat, |
16 repository, | |
16 util, | 17 util, |
17 wireproto, | 18 wireproto, |
18 ) | 19 ) |
19 | 20 |
20 def _serverquote(s): | 21 def _serverquote(s): |
112 return self._main.close() | 113 return self._main.close() |
113 | 114 |
114 def flush(self): | 115 def flush(self): |
115 return self._main.flush() | 116 return self._main.flush() |
116 | 117 |
117 class sshpeer(wireproto.wirepeer): | 118 class sshpeer(wireproto.wirepeer, repository.legacypeer): |
118 def __init__(self, ui, path, create=False): | 119 def __init__(self, ui, path, create=False): |
119 self._url = path | 120 self._url = path |
120 self.ui = ui | 121 self._ui = ui |
121 self._pipeo = self._pipei = self._pipee = None | 122 self._pipeo = self._pipei = self._pipee = None |
122 | 123 |
123 u = util.url(path, parsequery=False, parsefragment=False) | 124 u = util.url(path, parsequery=False, parsefragment=False) |
124 if u.scheme != 'ssh' or not u.host or u.path is None: | 125 if u.scheme != 'ssh' or not u.host or u.path is None: |
125 self._abort(error.RepoError(_("couldn't parse location %s") % path)) | 126 self._abort(error.RepoError(_("couldn't parse location %s") % path)) |
148 if res != 0: | 149 if res != 0: |
149 self._abort(error.RepoError(_("could not create remote repo"))) | 150 self._abort(error.RepoError(_("could not create remote repo"))) |
150 | 151 |
151 self._validaterepo(sshcmd, args, remotecmd) | 152 self._validaterepo(sshcmd, args, remotecmd) |
152 | 153 |
154 # TODO remove this alias once peerrepository inheritance is removed. | |
155 self._capabilities = self.capabilities | |
156 | |
157 # Begin of _basepeer interface. | |
158 | |
159 @util.propertycache | |
160 def ui(self): | |
161 return self._ui | |
162 | |
153 def url(self): | 163 def url(self): |
154 return self._url | 164 return self._url |
165 | |
166 def local(self): | |
167 return None | |
168 | |
169 def peer(self): | |
170 return self | |
171 | |
172 def canpush(self): | |
173 return True | |
174 | |
175 def close(self): | |
176 pass | |
177 | |
178 # End of _basepeer interface. | |
179 | |
180 # Begin of _basewirecommands interface. | |
181 | |
182 def capabilities(self): | |
183 return self._caps | |
184 | |
185 # End of _basewirecommands interface. | |
155 | 186 |
156 def _validaterepo(self, sshcmd, args, remotecmd): | 187 def _validaterepo(self, sshcmd, args, remotecmd): |
157 # cleanup up previous run | 188 # cleanup up previous run |
158 self._cleanup() | 189 self._cleanup() |
159 | 190 |
197 self._caps = set() | 228 self._caps = set() |
198 for l in reversed(lines): | 229 for l in reversed(lines): |
199 if l.startswith("capabilities:"): | 230 if l.startswith("capabilities:"): |
200 self._caps.update(l[:-1].split(":")[1].split()) | 231 self._caps.update(l[:-1].split(":")[1].split()) |
201 break | 232 break |
202 | |
203 def _capabilities(self): | |
204 return self._caps | |
205 | 233 |
206 def _readerr(self): | 234 def _readerr(self): |
207 _forwardoutput(self.ui, self._pipee) | 235 _forwardoutput(self.ui, self._pipee) |
208 | 236 |
209 def _abort(self, exception): | 237 def _abort(self, exception): |