diff --git a/rhodecode/lib/middleware/simplehg.py b/rhodecode/lib/middleware/simplehg.py --- a/rhodecode/lib/middleware/simplehg.py +++ b/rhodecode/lib/middleware/simplehg.py @@ -27,6 +27,7 @@ import os import logging import traceback +import urllib from mercurial.error import RepoError from mercurial.hgweb import hgweb_mod @@ -45,13 +46,21 @@ log = logging.getLogger(__name__) def is_mercurial(environ): - """Returns True if request's target is mercurial server - header + """ + Returns True if request's target is mercurial server - header ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. """ http_accept = environ.get('HTTP_ACCEPT') + path_info = environ['PATH_INFO'] if http_accept and http_accept.startswith('application/mercurial'): - return True - return False + ishg_path = True + else: + ishg_path = False + + log.debug('pathinfo: %s detected as HG %s' % ( + path_info, ishg_path) + ) + return ishg_path class SimpleHg(BaseVCSController): @@ -80,12 +89,12 @@ class SimpleHg(BaseVCSController): # GET ACTION PULL or PUSH #====================================================================== action = self.__get_action(environ) + #====================================================================== # CHECK ANONYMOUS PERMISSION #====================================================================== if action in ['pull', 'push']: anonymous_user = self.__get_user('default') - username = anonymous_user.username anonymous_perm = self._check_permission(action, anonymous_user, repo_name) @@ -132,21 +141,23 @@ class SimpleHg(BaseVCSController): start_response) #check permissions for this repository - perm = self._check_permission(action, user, - repo_name) + perm = self._check_permission(action, user, repo_name) if perm is not True: return HTTPForbidden()(environ, start_response) - extras = {'ip': ipaddr, - 'username': username, - 'action': action, - 'repository': repo_name} + # extras are injected into mercurial UI object and later available + # in hg hooks executed by rhodecode + extras = { + 'ip': ipaddr, + 'username': username, + 'action': action, + 'repository': repo_name + } #====================================================================== # MERCURIAL REQUEST HANDLING #====================================================================== - - repo_path = safe_str(os.path.join(self.basepath, repo_name)) + repo_path = os.path.join(safe_str(self.basepath), safe_str(repo_name)) log.debug('Repository path is %s' % repo_path) baseui = make_ui('db')