aboutsummaryrefslogtreecommitdiff
path: root/rhodecode/lib/middleware/simplegit.py
diff options
context:
space:
mode:
Diffstat (limited to 'rhodecode/lib/middleware/simplegit.py')
-rw-r--r--rhodecode/lib/middleware/simplegit.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/rhodecode/lib/middleware/simplegit.py b/rhodecode/lib/middleware/simplegit.py
index 47acf7cf..59c6f1ae 100644
--- a/rhodecode/lib/middleware/simplegit.py
+++ b/rhodecode/lib/middleware/simplegit.py
@@ -25,6 +25,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
+import re
import logging
import traceback
@@ -79,21 +80,20 @@ from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
log = logging.getLogger(__name__)
-def is_git(environ):
- """Returns True if request's target is git server.
- ``HTTP_USER_AGENT`` would then have git client version given.
+GIT_PROTO_PAT = re.compile(r'^/(.+)/(info/refs|git-upload-pack|git-receive-pack)')
+
- :param environ:
- """
- http_user_agent = environ.get('HTTP_USER_AGENT')
- if http_user_agent and http_user_agent.startswith('git'):
- return True
- return False
+def is_git(environ):
+ path_info = environ['PATH_INFO']
+ isgit_path = GIT_PROTO_PAT.match(path_info)
+ log.debug('is a git path %s pathinfo : %s' % (isgit_path, path_info))
+ return isgit_path
class SimpleGit(BaseVCSController):
def _handle_request(self, environ, start_response):
+
if not is_git(environ):
return self.application(environ, start_response)
@@ -218,13 +218,11 @@ class SimpleGit(BaseVCSController):
"""
try:
environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO'])
- repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:])
- if repo_name.endswith('/'):
- repo_name = repo_name.rstrip('/')
+ repo_name = GIT_PROTO_PAT.match(environ['PATH_INFO']).group(1)
except:
log.error(traceback.format_exc())
raise
- repo_name = repo_name.split('/')[0]
+
return repo_name
def __get_user(self, username):
@@ -238,9 +236,10 @@ class SimpleGit(BaseVCSController):
service = environ['QUERY_STRING'].split('=')
if len(service) > 1:
service_cmd = service[1]
- mapping = {'git-receive-pack': 'push',
- 'git-upload-pack': 'pull',
- }
+ mapping = {
+ 'git-receive-pack': 'push',
+ 'git-upload-pack': 'pull',
+ }
return mapping.get(service_cmd,
service_cmd if service_cmd else 'other')