comparison rhodecode/lib/middleware/simplegit.py @ 2052:320806ff6be2 beta

fixes git-protocol with
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 27 Feb 2012 07:46:52 +0200
parents c6e288dcb4a2
children 851ea1139169
comparison
equal deleted inserted replaced
2050:6aa328b903a5 2052:320806ff6be2
23 # 23 #
24 # You should have received a copy of the GNU General Public License 24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. 25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26
27 import os 27 import os
28 import re
28 import logging 29 import logging
29 import traceback 30 import traceback
30 31
31 from dulwich import server as dulserver 32 from dulwich import server as dulserver
32 33
75 from rhodecode.model.db import User 76 from rhodecode.model.db import User
76 77
77 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError 78 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
78 79
79 log = logging.getLogger(__name__) 80 log = logging.getLogger(__name__)
81
82
83 GIT_PROTO_PAT = re.compile(r'git-upload-pack|git-receive-pack|info\/refs')
80 84
81 85
82 def is_git(environ): 86 def is_git(environ):
83 """Returns True if request's target is git server. 87 """Returns True if request's target is git server.
84 ``HTTP_USER_AGENT`` would then have git client version given. 88 ``HTTP_USER_AGENT`` would then have git client version given.
217 :param environ: environ where PATH_INFO is stored 221 :param environ: environ where PATH_INFO is stored
218 """ 222 """
219 try: 223 try:
220 environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO']) 224 environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO'])
221 repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:]) 225 repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:])
226 repo_name = GIT_PROTO_PAT.split(repo_name)
227 if repo_name:
228 repo_name = repo_name[0]
229
222 if repo_name.endswith('/'): 230 if repo_name.endswith('/'):
223 repo_name = repo_name.rstrip('/') 231 repo_name = repo_name.rstrip('/')
224 except: 232 except:
225 log.error(traceback.format_exc()) 233 log.error(traceback.format_exc())
226 raise 234 raise
227 repo_name = repo_name.split('/')[0] 235
228 return repo_name 236 return repo_name
229 237
230 def __get_user(self, username): 238 def __get_user(self, username):
231 return User.get_by_username(username) 239 return User.get_by_username(username)
232 240