##// 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 import cPickle as pickle
8 import cPickle as pickle
9 import tempfile
9 import tempfile
10 import urllib
10 import urllib
11 import urllib2
11
12
12 from mercurial import strutil, util, encoding
13 from mercurial import strutil, util, encoding
13 from mercurial.i18n import _
14 from mercurial.i18n import _
@@ -136,7 +137,7 b' class logstream(object):'
136 # Check to see if the given path is a local Subversion repo. Verify this by
137 # Check to see if the given path is a local Subversion repo. Verify this by
137 # looking for several svn-specific files and directories in the given
138 # looking for several svn-specific files and directories in the given
138 # directory.
139 # directory.
139 def filecheck(path, proto):
140 def filecheck(ui, path, proto):
140 for x in ('locks', 'hooks', 'format', 'db', ):
141 for x in ('locks', 'hooks', 'format', 'db', ):
141 if not os.path.exists(os.path.join(path, x)):
142 if not os.path.exists(os.path.join(path, x)):
142 return False
143 return False
@@ -145,15 +146,27 b' def filecheck(path, proto):'
145 # Check to see if a given path is the root of an svn repo over http. We verify
146 # Check to see if a given path is the root of an svn repo over http. We verify
146 # this by requesting a version-controlled URL we know can't exist and looking
147 # this by requesting a version-controlled URL we know can't exist and looking
147 # for the svn-specific "not found" XML.
148 # for the svn-specific "not found" XML.
148 def httpcheck(path, proto):
149 def httpcheck(ui, path, proto):
149 return ('<m:human-readable errcode="160013">' in
150 try:
150 urllib.urlopen('%s://%s/!svn/ver/0/.svn' % (proto, path)).read())
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 protomap = {'http': httpcheck,
165 protomap = {'http': httpcheck,
153 'https': httpcheck,
166 'https': httpcheck,
154 'file': filecheck,
167 'file': filecheck,
155 }
168 }
156 def issvnurl(url):
169 def issvnurl(ui, url):
157 try:
170 try:
158 proto, path = url.split('://', 1)
171 proto, path = url.split('://', 1)
159 if proto == 'file':
172 if proto == 'file':
@@ -165,7 +178,7 b' def issvnurl(url):'
165 path = path.replace(os.sep, '/')
178 path = path.replace(os.sep, '/')
166 check = protomap.get(proto, lambda p, p2: False)
179 check = protomap.get(proto, lambda p, p2: False)
167 while '/' in path:
180 while '/' in path:
168 if check(path, proto):
181 if check(ui, path, proto):
169 return True
182 return True
170 path = path.rsplit('/', 1)[0]
183 path = path.rsplit('/', 1)[0]
171 return False
184 return False
@@ -191,7 +204,7 b' class svn_source(converter_source):'
191 if not (url.startswith('svn://') or url.startswith('svn+ssh://') or
204 if not (url.startswith('svn://') or url.startswith('svn+ssh://') or
192 (os.path.exists(url) and
205 (os.path.exists(url) and
193 os.path.exists(os.path.join(url, '.svn'))) or
206 os.path.exists(os.path.join(url, '.svn'))) or
194 issvnurl(url)):
207 issvnurl(ui, url)):
195 raise NoRepo("%s does not look like a Subversion repo" % url)
208 raise NoRepo("%s does not look like a Subversion repo" % url)
196
209
197 try:
210 try:
General Comments 0
You need to be logged in to leave comments. Login now