# HG changeset patch # User Mads Kiilerich # Date 1534285044 -7200 # Node ID 61bd3efe4a6c2f68e88313d0aa237188145fa558 # Parent 6af08d44daa805bc6d4629ebec236cbef35efd2d middleware: align hg and git implementations - make it more clear that we have code duplication and something probably should be reused diff -r 6af08d44daa8 -r 61bd3efe4a6c kallithea/lib/middleware/simplegit.py --- a/kallithea/lib/middleware/simplegit.py Wed Aug 08 02:23:11 2018 +0200 +++ b/kallithea/lib/middleware/simplegit.py Wed Aug 15 00:17:24 2018 +0200 @@ -15,7 +15,7 @@ kallithea.lib.middleware.simplegit ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -SimpleGit middleware for handling git protocol request (push/clone etc.) +SimpleGit middleware for handling Git protocol requests (push/clone etc.) It's implemented with basic auth function This file was forked by the Kallithea project in July 2014. @@ -44,7 +44,6 @@ from kallithea.lib.utils import make_ui, is_valid_repo from kallithea.lib.exceptions import HTTPLockedRC from kallithea.lib.hooks import pull_lock_handling -from kallithea.lib import auth_modules log = logging.getLogger(__name__) @@ -100,8 +99,8 @@ if response_app is not None: return response_app(environ, start_response) - # extras are injected into UI object and later available - # in hooks executed by kallithea + # extras are injected into Mercurial UI object and later available + # in hooks executed by Kallithea from kallithea import CONFIG server_url = get_server_url(environ) extras = { @@ -119,10 +118,9 @@ #=================================================================== # GIT REQUEST HANDLING #=================================================================== - repo_path = os.path.join(safe_str(self.basepath),str_repo_name) + repo_path = os.path.join(safe_str(self.basepath), str_repo_name) log.debug('Repository path is %s', repo_path) - # CHECK LOCKING only if it's not ANONYMOUS USER if not user.is_default_user: log.debug('Checking locking on repository') make_lock, locked, locked_by = check_locking_state(action, repo_name, user) @@ -181,7 +179,7 @@ def __get_action(self, environ): """ - Maps git request commands into a pull or push command. + Maps Git request commands into a pull or push command. :param environ: """ diff -r 6af08d44daa8 -r 61bd3efe4a6c kallithea/lib/middleware/simplehg.py --- a/kallithea/lib/middleware/simplehg.py Wed Aug 08 02:23:11 2018 +0200 +++ b/kallithea/lib/middleware/simplehg.py Wed Aug 15 00:17:24 2018 +0200 @@ -15,8 +15,8 @@ kallithea.lib.middleware.simplehg ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -SimpleHg middleware for handling mercurial protocol request -(push/clone etc.). It's implemented with basic auth function +SimpleHg middleware for handling Mercurial protocol requests (push/clone etc.). +It's implemented with basic auth function This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: @@ -77,10 +77,8 @@ # EXTRACT REPOSITORY NAME FROM ENV #====================================================================== try: - str_repo_name = environ['REPO_NAME'] = self.__get_repository(environ) - assert isinstance(str_repo_name, str), str_repo_name + str_repo_name = self.__get_repository(environ) repo_name = safe_unicode(str_repo_name) - assert safe_str(repo_name) == str_repo_name, (str_repo_name, repo_name) log.debug('Extracted repo name is %s', repo_name) except Exception as e: log.error('error extracting repo_name: %r', e) @@ -105,8 +103,8 @@ if response_app is not None: return response_app(environ, start_response) - # extras are injected into mercurial UI object and later available - # in hg hooks executed by kallithea + # extras are injected into Mercurial UI object and later available + # in hooks executed by Kallithea from kallithea import CONFIG server_url = get_server_url(environ) extras = { @@ -148,6 +146,7 @@ try: log.info('%s action on Mercurial repo "%s" by "%s" from %s', action, str_repo_name, safe_str(user.username), ip_addr) + environ['REPO_NAME'] = str_repo_name # used by hgweb_mod.hgweb app = self.__make_app(repo_path, baseui, extras) return app(environ, start_response) except RepoError as e: @@ -206,7 +205,7 @@ def __get_action(self, environ): """ - Maps mercurial request commands into a pull or push command. + Maps Mercurial request commands into a pull or push command. Raises HTTPBadRequest if the request environment doesn't look like a hg client. """