##// END OF EJS Templates
Added url validator for git
marcink -
r2704:959d0daa beta
parent child Browse files
Show More
@@ -15,6 +15,8 b' import time'
15 15 import posixpath
16 16 import logging
17 17 import traceback
18 import urllib
19 import urllib2
18 20 from dulwich.repo import Repo, NotGitRepository
19 21 #from dulwich.config import ConfigFile
20 22 from string import Template
@@ -126,7 +128,8 b' class GitRepository(BaseRepository):'
126 128 se = None
127 129 return so, se
128 130
129 def _check_url(self, url):
131 @classmethod
132 def _check_url(cls, url):
130 133 """
131 134 Functon will check given url and try to verify if it's a valid
132 135 link. Sometimes it may happened that mercurial will issue basic
@@ -135,9 +138,45 b' class GitRepository(BaseRepository):'
135 138
136 139 On failures it'll raise urllib2.HTTPError
137 140 """
141 from mercurial.util import url as Url
138 142
139 #TODO: implement this
140 pass
143 # those authnadlers are patched for python 2.6.5 bug an
144 # infinit looping when given invalid resources
145 from mercurial.url import httpbasicauthhandler, httpdigestauthhandler
146
147 # check first if it's not an local url
148 if os.path.isdir(url) or url.startswith('file:'):
149 return True
150
151 if('+' in url[:url.find('://')]):
152 url = url[url.find('+') + 1:]
153
154 handlers = []
155 test_uri, authinfo = Url(url).authinfo()
156 if not test_uri.endswith('info/refs'):
157 test_uri = test_uri.rstrip('/') + '/info/refs'
158 if authinfo:
159 #create a password manager
160 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
161 passmgr.add_password(*authinfo)
162
163 handlers.extend((httpbasicauthhandler(passmgr),
164 httpdigestauthhandler(passmgr)))
165
166 o = urllib2.build_opener(*handlers)
167 o.addheaders = [('User-Agent', 'git/1.7.8.0')] # fake some git
168
169 q = {"service": 'git-upload-pack'}
170 qs = '?%s' % urllib.urlencode(q)
171 cu = "%s%s" % (test_uri, qs)
172 req = urllib2.Request(cu, None, {})
173
174 try:
175 resp = o.open(req)
176 return resp.code == 200
177 except Exception, e:
178 # means it cannot be cloned
179 raise urllib2.URLError(e)
141 180
142 181 def _get_repo(self, create, src_url=None, update_after_clone=False,
143 182 bare=False):
@@ -148,7 +187,7 b' class GitRepository(BaseRepository):'
148 187 "given (clone operation creates repository)")
149 188 try:
150 189 if create and src_url:
151 self._check_url(src_url)
190 GitRepository._check_url(src_url)
152 191 self.clone(src_url, update_after_clone, bare)
153 192 return Repo(self.path)
154 193 elif create:
@@ -249,7 +249,8 b' class MercurialRepository(BaseRepository'
249 249 ignorews=ignore_whitespace,
250 250 context=context)))
251 251
252 def _check_url(self, url):
252 @classmethod
253 def _check_url(cls, url):
253 254 """
254 255 Function will check given url and try to verify if it's a valid
255 256 link. Sometimes it may happened that mercurial will issue basic
@@ -271,7 +272,7 b' class MercurialRepository(BaseRepository'
271 272 return True
272 273
273 274 if('+' in url[:url.find('://')]):
274 url = url[url.find('+')+1:]
275 url = url[url.find('+') + 1:]
275 276
276 277 handlers = []
277 278 test_uri, authinfo = Url(url).authinfo()
@@ -318,7 +319,7 b' class MercurialRepository(BaseRepository'
318 319 if not update_after_clone:
319 320 opts.update({'noupdate': True})
320 321 try:
321 self._check_url(url)
322 MercurialRepository._check_url(url)
322 323 clone(self.baseui, url, self.path, **opts)
323 324 # except urllib2.URLError:
324 325 # raise Abort("Got HTTP 404 error")
General Comments 0
You need to be logged in to leave comments. Login now