comparison mercurial/sshrepo.py @ 13819:d16894e29f91

httprepo/sshrepo: use url.url Like the previous patch to getauthinfo(), this also makes username/password parsing more forgiving for SSH URLs. This also opens up the possibility of allowing non-numeric ports, since the URL parser has no problem handling them. Related issues: - issue851: @ in password in http url - issue2055: nonnumeric port bug with https protocol
author Brodie Rao <brodie@bitheap.org>
date Wed, 30 Mar 2011 20:01:35 -0700
parents 3458c15ab2f0
children f1823b9f073b
comparison
equal deleted inserted replaced
13818:bf6156bab41b 13819:d16894e29f91
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from i18n import _ 8 from i18n import _
9 import util, error, wireproto 9 import util, error, wireproto, url
10 import re
11 10
12 class remotelock(object): 11 class remotelock(object):
13 def __init__(self, repo): 12 def __init__(self, repo):
14 self.repo = repo 13 self.repo = repo
15 def release(self): 14 def release(self):
22 class sshrepository(wireproto.wirerepository): 21 class sshrepository(wireproto.wirerepository):
23 def __init__(self, ui, path, create=0): 22 def __init__(self, ui, path, create=0):
24 self._url = path 23 self._url = path
25 self.ui = ui 24 self.ui = ui
26 25
27 m = re.match(r'^ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?$', path) 26 u = url.url(path, parse_query=False, parse_fragment=False)
28 if not m: 27 if u.scheme != 'ssh' or not u.host or u.path is None:
29 self._abort(error.RepoError(_("couldn't parse location %s") % path)) 28 self._abort(error.RepoError(_("couldn't parse location %s") % path))
30 29
31 self.user = m.group(2) 30 self.user = u.user
32 if self.user and ':' in self.user: 31 if u.passwd is not None:
33 self._abort(error.RepoError(_("password in URL not supported"))) 32 self._abort(error.RepoError(_("password in URL not supported")))
34 self.host = m.group(3) 33 self.host = u.host
35 self.port = m.group(5) 34 self.port = u.port
36 self.path = m.group(7) or "." 35 self.path = u.path or "."
37 36
38 sshcmd = self.ui.config("ui", "ssh", "ssh") 37 sshcmd = self.ui.config("ui", "ssh", "ssh")
39 remotecmd = self.ui.config("ui", "remotecmd", "hg") 38 remotecmd = self.ui.config("ui", "remotecmd", "hg")
40 39
41 args = util.sshargs(sshcmd, self.host, self.user, self.port) 40 args = util.sshargs(sshcmd, self.host, self.user, self.port)