##// END OF EJS Templates
convert/svn: delegate to svn bindings if HTTP probe fails...
Patrick Mezard -
r9829:1b2516a5 default
parent child Browse files
Show More
@@ -8,6 +8,7 b' import sys'
8 8 import cPickle as pickle
9 9 import tempfile
10 10 import urllib
11 import urllib2
11 12
12 13 from mercurial import strutil, util, encoding
13 14 from mercurial.i18n import _
@@ -136,7 +137,7 b' class logstream(object):'
136 137 # Check to see if the given path is a local Subversion repo. Verify this by
137 138 # looking for several svn-specific files and directories in the given
138 139 # directory.
139 def filecheck(path, proto):
140 def filecheck(ui, path, proto):
140 141 for x in ('locks', 'hooks', 'format', 'db', ):
141 142 if not os.path.exists(os.path.join(path, x)):
142 143 return False
@@ -145,15 +146,27 b' def filecheck(path, proto):'
145 146 # Check to see if a given path is the root of an svn repo over http. We verify
146 147 # this by requesting a version-controlled URL we know can't exist and looking
147 148 # for the svn-specific "not found" XML.
148 def httpcheck(path, proto):
149 return ('<m:human-readable errcode="160013">' in
150 urllib.urlopen('%s://%s/!svn/ver/0/.svn' % (proto, path)).read())
149 def httpcheck(ui, path, proto):
150 try:
151 opener = urllib2.build_opener()
152 rsp = opener.open('%s://%s/!svn/ver/0/.svn' % (proto, path))
153 return '<m:human-readable errcode="160013">' in rsp.read()
154 except urllib2.HTTPError, inst:
155 if inst.code == 404:
156 return False
157 # Except for 404 we cannot know for sure this is not an svn repo
158 ui.warn(_('svn: cannot probe remote repository, assume it could be '
159 'a subversion repository. Use --source if you know better.\n'))
160 return True
161 except:
162 # Could be urllib2.URLError if the URL is invalid or anything else.
163 return False
151 164
152 165 protomap = {'http': httpcheck,
153 166 'https': httpcheck,
154 167 'file': filecheck,
155 168 }
156 def issvnurl(url):
169 def issvnurl(ui, url):
157 170 try:
158 171 proto, path = url.split('://', 1)
159 172 if proto == 'file':
@@ -165,7 +178,7 b' def issvnurl(url):'
165 178 path = path.replace(os.sep, '/')
166 179 check = protomap.get(proto, lambda p, p2: False)
167 180 while '/' in path:
168 if check(path, proto):
181 if check(ui, path, proto):
169 182 return True
170 183 path = path.rsplit('/', 1)[0]
171 184 return False
@@ -191,7 +204,7 b' class svn_source(converter_source):'
191 204 if not (url.startswith('svn://') or url.startswith('svn+ssh://') or
192 205 (os.path.exists(url) and
193 206 os.path.exists(os.path.join(url, '.svn'))) or
194 issvnurl(url)):
207 issvnurl(ui, url)):
195 208 raise NoRepo("%s does not look like a Subversion repo" % url)
196 209
197 210 try:
General Comments 0
You need to be logged in to leave comments. Login now