Mercurial > hg-stable
changeset 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 |
files | mercurial/sshpeer.py tests/test-check-interfaces.py |
diffstat | 2 files changed, 23 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/sshpeer.py Sun Feb 04 12:55:18 2018 -0800 +++ b/mercurial/sshpeer.py Sun Feb 04 19:23:40 2018 -0800 @@ -115,35 +115,15 @@ return self._main.flush() class sshpeer(wireproto.wirepeer): - def __init__(self, ui, path, create=False): + def __init__(self, ui, path, create=False, sshstate=None): self._url = path self._ui = ui self._pipeo = self._pipei = self._pipee = None u = util.url(path, parsequery=False, parsefragment=False) - - self._user = u.user - self._host = u.host - self._port = u.port self._path = u.path or '.' - sshcmd = self.ui.config("ui", "ssh") - remotecmd = self.ui.config("ui", "remotecmd") - sshaddenv = dict(self.ui.configitems("sshenv")) - sshenv = util.shellenviron(sshaddenv) - - args = util.sshargs(sshcmd, self._host, self._user, self._port) - - if create: - cmd = '%s %s %s' % (sshcmd, args, - util.shellquote("%s init %s" % - (_serverquote(remotecmd), _serverquote(self._path)))) - ui.debug('running %s\n' % cmd) - res = ui.system(cmd, blockedtag='sshpeer', environ=sshenv) - if res != 0: - self._abort(error.RepoError(_("could not create remote repo"))) - - self._validaterepo(sshcmd, args, remotecmd, sshenv) + self._validaterepo(*sshstate) # Begin of _basepeer interface. @@ -377,4 +357,23 @@ if u.passwd is not None: raise error.RepoError(_('password in URL not supported')) - return sshpeer(ui, path, create=create) + sshcmd = ui.config('ui', 'ssh') + remotecmd = ui.config('ui', 'remotecmd') + sshaddenv = dict(ui.configitems('sshenv')) + sshenv = util.shellenviron(sshaddenv) + remotepath = u.path or '.' + + args = util.sshargs(sshcmd, u.host, u.user, u.port) + + if create: + cmd = '%s %s %s' % (sshcmd, args, + util.shellquote('%s init %s' % + (_serverquote(remotecmd), _serverquote(remotepath)))) + ui.debug('running %s\n' % cmd) + res = ui.system(cmd, blockedtag='sshpeer', environ=sshenv) + if res != 0: + raise error.RepoError(_('could not create remote repo')) + + sshstate = (sshcmd, args, remotecmd, sshenv) + + return sshpeer(ui, path, create=create, sshstate=sshstate)
--- a/tests/test-check-interfaces.py Sun Feb 04 12:55:18 2018 -0800 +++ b/tests/test-check-interfaces.py Sun Feb 04 19:23:40 2018 -0800 @@ -69,7 +69,7 @@ checkobject(badpeer()) checkobject(httppeer.httppeer(ui, 'http://localhost')) checkobject(localrepo.localpeer(dummyrepo())) - checkobject(testingsshpeer(ui, 'ssh://localhost/foo')) + checkobject(testingsshpeer(ui, 'ssh://localhost/foo', False, ())) checkobject(bundlerepo.bundlepeer(dummyrepo())) checkobject(statichttprepo.statichttppeer(dummyrepo())) checkobject(unionrepo.unionpeer(dummyrepo()))