Changeset - 96e26544d037
[Not reviewed]
default
0 3 0
Mads Kiilerich - 7 years ago 2019-01-08 13:04:19
mads@kiilerich.com
middleware: introduce BaseVCSController scm_alias - prepare for sharing shared code
3 files changed with 14 insertions and 8 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/base.py
Show inline comments
 
@@ -192,6 +192,8 @@ class BaseVCSController(object):
 
    (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
kallithea/lib/middleware/simplegit.py
Show inline comments
 
@@ -57,6 +57,8 @@ cmd_mapping = {
 

	
 
class SimpleGit(BaseVCSController):
 

	
 
    scm_alias = 'git'
 

	
 
    @classmethod
 
    def parse_request(cls, environ):
 
        path_info = environ.get('PATH_INFO', '')
 
@@ -85,7 +87,7 @@ class SimpleGit(BaseVCSController):
 
        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 @@ class SimpleGit(BaseVCSController):
 
            '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 @@ class SimpleGit(BaseVCSController):
 

	
 
        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:
kallithea/lib/middleware/simplehg.py
Show inline comments
 
@@ -96,6 +96,8 @@ cmd_mapping = {
 

	
 
class SimpleHg(BaseVCSController):
 

	
 
    scm_alias = 'hg'
 

	
 
    @classmethod
 
    def parse_request(cls, environ):
 
        http_accept = environ.get('HTTP_ACCEPT', '')
 
@@ -140,7 +142,7 @@ class SimpleHg(BaseVCSController):
 
        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 @@ class SimpleHg(BaseVCSController):
 
            '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 @@ class SimpleHg(BaseVCSController):
 
        _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)
0 comments (0 inline, 0 general)