mercurial/sshpeer.py
changeset 35932 31449baf0936
parent 35931 b202d360d2a4
child 35933 805edf16e8e0
equal deleted inserted replaced
35931:b202d360d2a4 35932: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)