##// 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 import posixpath
15 import posixpath
16 import logging
16 import logging
17 import traceback
17 import traceback
18 import urllib
19 import urllib2
18 from dulwich.repo import Repo, NotGitRepository
20 from dulwich.repo import Repo, NotGitRepository
19 #from dulwich.config import ConfigFile
21 #from dulwich.config import ConfigFile
20 from string import Template
22 from string import Template
@@ -126,7 +128,8 b' class GitRepository(BaseRepository):'
126 se = None
128 se = None
127 return so, se
129 return so, se
128
130
129 def _check_url(self, url):
131 @classmethod
132 def _check_url(cls, url):
130 """
133 """
131 Functon will check given url and try to verify if it's a valid
134 Functon will check given url and try to verify if it's a valid
132 link. Sometimes it may happened that mercurial will issue basic
135 link. Sometimes it may happened that mercurial will issue basic
@@ -135,9 +138,45 b' class GitRepository(BaseRepository):'
135
138
136 On failures it'll raise urllib2.HTTPError
139 On failures it'll raise urllib2.HTTPError
137 """
140 """
141 from mercurial.util import url as Url
138
142
139 #TODO: implement this
143 # those authnadlers are patched for python 2.6.5 bug an
140 pass
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 def _get_repo(self, create, src_url=None, update_after_clone=False,
181 def _get_repo(self, create, src_url=None, update_after_clone=False,
143 bare=False):
182 bare=False):
@@ -148,7 +187,7 b' class GitRepository(BaseRepository):'
148 "given (clone operation creates repository)")
187 "given (clone operation creates repository)")
149 try:
188 try:
150 if create and src_url:
189 if create and src_url:
151 self._check_url(src_url)
190 GitRepository._check_url(src_url)
152 self.clone(src_url, update_after_clone, bare)
191 self.clone(src_url, update_after_clone, bare)
153 return Repo(self.path)
192 return Repo(self.path)
154 elif create:
193 elif create:
@@ -249,7 +249,8 b' class MercurialRepository(BaseRepository'
249 ignorews=ignore_whitespace,
249 ignorews=ignore_whitespace,
250 context=context)))
250 context=context)))
251
251
252 def _check_url(self, url):
252 @classmethod
253 def _check_url(cls, url):
253 """
254 """
254 Function will check given url and try to verify if it's a valid
255 Function will check given url and try to verify if it's a valid
255 link. Sometimes it may happened that mercurial will issue basic
256 link. Sometimes it may happened that mercurial will issue basic
@@ -318,7 +319,7 b' class MercurialRepository(BaseRepository'
318 if not update_after_clone:
319 if not update_after_clone:
319 opts.update({'noupdate': True})
320 opts.update({'noupdate': True})
320 try:
321 try:
321 self._check_url(url)
322 MercurialRepository._check_url(url)
322 clone(self.baseui, url, self.path, **opts)
323 clone(self.baseui, url, self.path, **opts)
323 # except urllib2.URLError:
324 # except urllib2.URLError:
324 # raise Abort("Got HTTP 404 error")
325 # raise Abort("Got HTTP 404 error")
General Comments 0
You need to be logged in to leave comments. Login now