Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/sshpeer.py @ 35972:31449baf0936
sshpeer: move ssh command and repo creation logic out of __init__
It was easier to move both of these at once because repository
creation requires various variables and I didn't want to add
tons of arguments and code to __init__ that will soon be deleted
anyway. We do add an extra argument so we can proxy values to the
_validaterepo() call. But this is minimally invasive.
Some callers of self._abort() were converted to just raise. Like
before, the _abort() call wasn't necessary because self._pipe*
aren't populated this early in the object's lifetime.
As part of this, various private attributes derived from the parsed
URL are no longer used. So we no longer set them.
Differential Revision: https://phab.mercurial-scm.org/D2028
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 04 Feb 2018 19:23:40 -0800 |
parents | b202d360d2a4 |
children | 805edf16e8e0 |
comparison
equal
deleted
inserted
replaced
35971:b202d360d2a4 | 35972:31449baf0936 |
---|---|
113 | 113 |
114 def flush(self): | 114 def flush(self): |
115 return self._main.flush() | 115 return self._main.flush() |
116 | 116 |
117 class sshpeer(wireproto.wirepeer): | 117 class sshpeer(wireproto.wirepeer): |
118 def __init__(self, ui, path, create=False): | 118 def __init__(self, ui, path, create=False, sshstate=None): |
119 self._url = path | 119 self._url = path |
120 self._ui = ui | 120 self._ui = ui |
121 self._pipeo = self._pipei = self._pipee = None | 121 self._pipeo = self._pipei = self._pipee = None |
122 | 122 |
123 u = util.url(path, parsequery=False, parsefragment=False) | 123 u = util.url(path, parsequery=False, parsefragment=False) |
124 | |
125 self._user = u.user | |
126 self._host = u.host | |
127 self._port = u.port | |
128 self._path = u.path or '.' | 124 self._path = u.path or '.' |
129 | 125 |
130 sshcmd = self.ui.config("ui", "ssh") | 126 self._validaterepo(*sshstate) |
131 remotecmd = self.ui.config("ui", "remotecmd") | |
132 sshaddenv = dict(self.ui.configitems("sshenv")) | |
133 sshenv = util.shellenviron(sshaddenv) | |
134 | |
135 args = util.sshargs(sshcmd, self._host, self._user, self._port) | |
136 | |
137 if create: | |
138 cmd = '%s %s %s' % (sshcmd, args, | |
139 util.shellquote("%s init %s" % | |
140 (_serverquote(remotecmd), _serverquote(self._path)))) | |
141 ui.debug('running %s\n' % cmd) | |
142 res = ui.system(cmd, blockedtag='sshpeer', environ=sshenv) | |
143 if res != 0: | |
144 self._abort(error.RepoError(_("could not create remote repo"))) | |
145 | |
146 self._validaterepo(sshcmd, args, remotecmd, sshenv) | |
147 | 127 |
148 # Begin of _basepeer interface. | 128 # Begin of _basepeer interface. |
149 | 129 |
150 @util.propertycache | 130 @util.propertycache |
151 def ui(self): | 131 def ui(self): |
375 util.checksafessh(path) | 355 util.checksafessh(path) |
376 | 356 |
377 if u.passwd is not None: | 357 if u.passwd is not None: |
378 raise error.RepoError(_('password in URL not supported')) | 358 raise error.RepoError(_('password in URL not supported')) |
379 | 359 |
380 return sshpeer(ui, path, create=create) | 360 sshcmd = ui.config('ui', 'ssh') |
361 remotecmd = ui.config('ui', 'remotecmd') | |
362 sshaddenv = dict(ui.configitems('sshenv')) | |
363 sshenv = util.shellenviron(sshaddenv) | |
364 remotepath = u.path or '.' | |
365 | |
366 args = util.sshargs(sshcmd, u.host, u.user, u.port) | |
367 | |
368 if create: | |
369 cmd = '%s %s %s' % (sshcmd, args, | |
370 util.shellquote('%s init %s' % | |
371 (_serverquote(remotecmd), _serverquote(remotepath)))) | |
372 ui.debug('running %s\n' % cmd) | |
373 res = ui.system(cmd, blockedtag='sshpeer', environ=sshenv) | |
374 if res != 0: | |
375 raise error.RepoError(_('could not create remote repo')) | |
376 | |
377 sshstate = (sshcmd, args, remotecmd, sshenv) | |
378 | |
379 return sshpeer(ui, path, create=create, sshstate=sshstate) |