diff rhodecode/lib/middleware/simplegit.py @ 2065:9ab21c5ddb84 rhodecode-0.0.1.3.2

merge with beta
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 28 Feb 2012 20:21:35 +0200
parents 82a88013a3fd 9f0fe6777833
children ecd59c28f432
line wrap: on
line diff
--- a/rhodecode/lib/middleware/simplegit.py	Mon Feb 27 05:14:08 2012 +0200
+++ b/rhodecode/lib/middleware/simplegit.py	Tue Feb 28 20:21:35 2012 +0200
@@ -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 @@
 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 @@
         """
         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 @@
         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')