Mercurial > kallithea
comparison rhodecode/lib/middleware/simplegit.py @ 2165:dc2584ba5fbc
merged beta into default branch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 28 Mar 2012 19:54:16 +0200 |
parents | ecd59c28f432 46b67235a8f0 |
children | a437a986d399 |
comparison
equal
deleted
inserted
replaced
2097:8fd6650bb436 | 2165:dc2584ba5fbc |
---|---|
63 'git-upload-pack': SimpleGitUploadPackHandler, | 63 'git-upload-pack': SimpleGitUploadPackHandler, |
64 'git-receive-pack': dulserver.ReceivePackHandler, | 64 'git-receive-pack': dulserver.ReceivePackHandler, |
65 } | 65 } |
66 | 66 |
67 from dulwich.repo import Repo | 67 from dulwich.repo import Repo |
68 from dulwich.web import HTTPGitApplication | 68 from dulwich.web import make_wsgi_chain |
69 | 69 |
70 from paste.httpheaders import REMOTE_USER, AUTH_TYPE | 70 from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
71 | 71 |
72 from rhodecode.lib import safe_str | 72 from rhodecode.lib.utils2 import safe_str |
73 from rhodecode.lib.base import BaseVCSController | 73 from rhodecode.lib.base import BaseVCSController |
74 from rhodecode.lib.auth import get_container_username | 74 from rhodecode.lib.auth import get_container_username |
75 from rhodecode.lib.utils import is_valid_repo | 75 from rhodecode.lib.utils import is_valid_repo |
76 from rhodecode.model.db import User | 76 from rhodecode.model.db import User |
77 | 77 |
84 | 84 |
85 | 85 |
86 def is_git(environ): | 86 def is_git(environ): |
87 path_info = environ['PATH_INFO'] | 87 path_info = environ['PATH_INFO'] |
88 isgit_path = GIT_PROTO_PAT.match(path_info) | 88 isgit_path = GIT_PROTO_PAT.match(path_info) |
89 log.debug('is a git path %s pathinfo : %s' % (isgit_path, path_info)) | 89 log.debug('pathinfo: %s detected as GIT %s' % ( |
90 path_info, isgit_path != None) | |
91 ) | |
90 return isgit_path | 92 return isgit_path |
91 | 93 |
92 | 94 |
93 class SimpleGit(BaseVCSController): | 95 class SimpleGit(BaseVCSController): |
94 | 96 |
111 repo_name = self.__get_repository(environ) | 113 repo_name = self.__get_repository(environ) |
112 log.debug('Extracted repo name is %s' % repo_name) | 114 log.debug('Extracted repo name is %s' % repo_name) |
113 except: | 115 except: |
114 return HTTPInternalServerError()(environ, start_response) | 116 return HTTPInternalServerError()(environ, start_response) |
115 | 117 |
118 # quick check if that dir exists... | |
119 if is_valid_repo(repo_name, self.basepath) is False: | |
120 return HTTPNotFound()(environ, start_response) | |
121 | |
116 #====================================================================== | 122 #====================================================================== |
117 # GET ACTION PULL or PUSH | 123 # GET ACTION PULL or PUSH |
118 #====================================================================== | 124 #====================================================================== |
119 action = self.__get_action(environ) | 125 action = self.__get_action(environ) |
120 | 126 |
121 #====================================================================== | 127 #====================================================================== |
122 # CHECK ANONYMOUS PERMISSION | 128 # CHECK ANONYMOUS PERMISSION |
123 #====================================================================== | 129 #====================================================================== |
124 | |
125 if action in ['pull', 'push']: | 130 if action in ['pull', 'push']: |
126 anonymous_user = self.__get_user('default') | 131 anonymous_user = self.__get_user('default') |
127 username = anonymous_user.username | 132 username = anonymous_user.username |
128 anonymous_perm = self._check_permission(action, anonymous_user, | 133 anonymous_perm = self._check_permission(action, anonymous_user, |
129 repo_name) | 134 repo_name) |
175 return HTTPForbidden()(environ, start_response) | 180 return HTTPForbidden()(environ, start_response) |
176 | 181 |
177 #=================================================================== | 182 #=================================================================== |
178 # GIT REQUEST HANDLING | 183 # GIT REQUEST HANDLING |
179 #=================================================================== | 184 #=================================================================== |
180 repo_path = safe_str(os.path.join(self.basepath, repo_name)) | 185 repo_path = os.path.join(safe_str(self.basepath), safe_str(repo_name)) |
181 log.debug('Repository path is %s' % repo_path) | 186 log.debug('Repository path is %s' % repo_path) |
182 | |
183 # quick check if that dir exists... | |
184 if is_valid_repo(repo_name, self.basepath) is False: | |
185 return HTTPNotFound()(environ, start_response) | |
186 | 187 |
187 try: | 188 try: |
188 #invalidate cache on push | 189 #invalidate cache on push |
189 if action == 'push': | 190 if action == 'push': |
190 self._invalidate_cache(repo_name) | 191 self._invalidate_cache(repo_name) |
202 :param repo_name: name of the repository | 203 :param repo_name: name of the repository |
203 :param repo_path: full path to the repository | 204 :param repo_path: full path to the repository |
204 """ | 205 """ |
205 _d = {'/' + repo_name: Repo(repo_path)} | 206 _d = {'/' + repo_name: Repo(repo_path)} |
206 backend = dulserver.DictBackend(_d) | 207 backend = dulserver.DictBackend(_d) |
207 gitserve = HTTPGitApplication(backend) | 208 gitserve = make_wsgi_chain(backend) |
208 | 209 |
209 return gitserve | 210 return gitserve |
210 | 211 |
211 def __get_repository(self, environ): | 212 def __get_repository(self, environ): |
212 """ | 213 """ |