##// END OF EJS Templates
sshpeer: move ssh command and repo creation logic out of __init__...
Gregory Szorc -
r35950:31449baf default
parent child Browse files
Show More
@@ -115,35 +115,15 b' class doublepipe(object):'
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
@@ -377,4 +357,23 b' def instance(ui, path, create):'
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)
@@ -69,7 +69,7 b' def main():'
69 checkobject(badpeer())
69 checkobject(badpeer())
70 checkobject(httppeer.httppeer(ui, 'http://localhost'))
70 checkobject(httppeer.httppeer(ui, 'http://localhost'))
71 checkobject(localrepo.localpeer(dummyrepo()))
71 checkobject(localrepo.localpeer(dummyrepo()))
72 checkobject(testingsshpeer(ui, 'ssh://localhost/foo'))
72 checkobject(testingsshpeer(ui, 'ssh://localhost/foo', False, ()))
73 checkobject(bundlerepo.bundlepeer(dummyrepo()))
73 checkobject(bundlerepo.bundlepeer(dummyrepo()))
74 checkobject(statichttprepo.statichttppeer(dummyrepo()))
74 checkobject(statichttprepo.statichttppeer(dummyrepo()))
75 checkobject(unionrepo.unionpeer(dummyrepo()))
75 checkobject(unionrepo.unionpeer(dummyrepo()))
General Comments 0
You need to be logged in to leave comments. Login now