# HG changeset patch # User Mads Kiilerich # Date 1546949059 -3600 # Node ID 96e26544d037e0cb96a7d30c5fb46631807674c1 # Parent 7e06657be365c15b91aa3e74d2e1504b2344d9a9 middleware: introduce BaseVCSController scm_alias - prepare for sharing shared code diff -r 7e06657be365 -r 96e26544d037 kallithea/lib/base.py --- a/kallithea/lib/base.py Fri Jan 11 02:02:01 2019 +0100 +++ b/kallithea/lib/base.py Tue Jan 08 13:04:19 2019 +0100 @@ -192,6 +192,8 @@ (coming from a VCS client, and not a browser). """ + scm_alias = None # 'hg' / 'git' + def __init__(self, application, config): self.application = application self.config = config diff -r 7e06657be365 -r 96e26544d037 kallithea/lib/middleware/simplegit.py --- a/kallithea/lib/middleware/simplegit.py Fri Jan 11 02:02:01 2019 +0100 +++ b/kallithea/lib/middleware/simplegit.py Tue Jan 08 13:04:19 2019 +0100 @@ -57,6 +57,8 @@ class SimpleGit(BaseVCSController): + scm_alias = 'git' + @classmethod def parse_request(cls, environ): path_info = environ.get('PATH_INFO', '') @@ -85,7 +87,7 @@ environ['pylons.status_code_redirect'] = True # quick check if repo exists... - if not is_valid_repo(parsed_request.repo_name, self.basepath, 'git'): + if not is_valid_repo(parsed_request.repo_name, self.basepath, self.scm_alias): raise HTTPNotFound() if parsed_request.action is None: @@ -108,7 +110,7 @@ 'username': user.username, 'action': parsed_request.action, 'repository': parsed_request.repo_name, - 'scm': 'git', + 'scm': self.scm_alias, 'config': CONFIG['__file__'], 'server_url': server_url, } @@ -122,8 +124,8 @@ try: self._handle_githooks(parsed_request.repo_name, parsed_request.action, baseui, environ) - log.info('%s action on Git repo "%s" by "%s" from %s', - parsed_request.action, parsed_request.repo_name, safe_str(user.username), ip_addr) + log.info('%s action on %s repo "%s" by "%s" from %s', + parsed_request.action, self.scm_alias, parsed_request.repo_name, safe_str(user.username), ip_addr) app = self.__make_app(parsed_request.repo_name) return app(environ, start_response) except Exception: diff -r 7e06657be365 -r 96e26544d037 kallithea/lib/middleware/simplehg.py --- a/kallithea/lib/middleware/simplehg.py Fri Jan 11 02:02:01 2019 +0100 +++ b/kallithea/lib/middleware/simplehg.py Tue Jan 08 13:04:19 2019 +0100 @@ -96,6 +96,8 @@ class SimpleHg(BaseVCSController): + scm_alias = 'hg' + @classmethod def parse_request(cls, environ): http_accept = environ.get('HTTP_ACCEPT', '') @@ -140,7 +142,7 @@ environ['pylons.status_code_redirect'] = True # quick check if repo exists... - if not is_valid_repo(parsed_request.repo_name, self.basepath, 'hg'): + if not is_valid_repo(parsed_request.repo_name, self.basepath, self.scm_alias): raise HTTPNotFound() if parsed_request.action is None: @@ -163,7 +165,7 @@ 'username': user.username, 'action': parsed_request.action, 'repository': parsed_request.repo_name, - 'scm': 'hg', + 'scm': self.scm_alias, 'config': CONFIG['__file__'], 'server_url': server_url, } @@ -179,8 +181,8 @@ _set_extras(extras or {}) try: - log.info('%s action on Mercurial repo "%s" by "%s" from %s', - parsed_request.action, parsed_request.repo_name, safe_str(user.username), ip_addr) + log.info('%s action on %s repo "%s" by "%s" from %s', + parsed_request.action, self.scm_alias, parsed_request.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) return app(environ, start_response)