diff --git a/rhodecode/lib/middleware/simplevcs.py b/rhodecode/lib/middleware/simplevcs.py --- a/rhodecode/lib/middleware/simplevcs.py +++ b/rhodecode/lib/middleware/simplevcs.py @@ -83,12 +83,15 @@ class SimpleVCS(object): SCM = 'unknown' + acl_repo_name = None + url_repo_name = None + vcs_repo_name = None + def __init__(self, application, config, registry): self.registry = registry self.application = application self.config = config # re-populated by specialized middleware - self.repo_name = None self.repo_vcs_config = base.Config() # base path of repo locations @@ -102,6 +105,11 @@ class SimpleVCS(object): self.ip_addr = '0.0.0.0' @property + def repo_name(self): + # TODO: johbo: Remove, switch to correct repo name attribute + return self.acl_repo_name + + @property def scm_app(self): custom_implementation = self.config.get('vcs.scm_app_implementation') if custom_implementation and custom_implementation != 'pyro4': @@ -340,7 +348,8 @@ class SimpleVCS(object): # REQUEST HANDLING # ====================================================================== str_repo_name = safe_str(self.repo_name) - repo_path = os.path.join(safe_str(self.basepath), str_repo_name) + repo_path = os.path.join( + safe_str(self.basepath), safe_str(self.vcs_repo_name)) log.debug('Repository path is %s', repo_path) fix_PATH() @@ -350,7 +359,7 @@ class SimpleVCS(object): action, self.SCM, str_repo_name, safe_str(username), ip_addr) return self._generate_vcs_response( - environ, start_response, repo_path, self.repo_name, extras, action) + environ, start_response, repo_path, self.url_repo_name, extras, action) @initialize_generator def _generate_vcs_response( @@ -365,7 +374,7 @@ class SimpleVCS(object): the first chunk is produced by the underlying WSGI application. """ callback_daemon, extras = self._prepare_callback_daemon(extras) - config = self._create_config(extras, repo_name) + config = self._create_config(extras, self.acl_repo_name) log.debug('HOOKS extras is %s', extras) app = self._create_wsgi_app(repo_path, repo_name, config) diff --git a/rhodecode/lib/middleware/vcs.py b/rhodecode/lib/middleware/vcs.py --- a/rhodecode/lib/middleware/vcs.py +++ b/rhodecode/lib/middleware/vcs.py @@ -176,18 +176,44 @@ class VCSMiddleware(object): environ['PATH_INFO'] = vcs_handler._get_by_id(environ['PATH_INFO']) repo_name = vcs_handler._get_repository_name(environ) + acl_repo_name = repo_name + vcs_repo_name = repo_name + url_repo_name = repo_name + pr_id = None + + # TODO: johbo: recognize a pull request based on pattern matching + if '/pull-request/' in repo_name: + acl_repo_name, other = repo_name.split('/pull-request/') + # TODO: johbo: Set shadow repo path + basename, repo_segment = acl_repo_name.rsplit('/', 1) + pr_id = int(other[0:-len('/repository')]) + vcs_repo_name = '{basename}/.__shadow_{repo_segment}_pr-{pr_id}'.format( + basename=basename, + repo_segment=repo_segment, + pr_id=pr_id) + + log.debug('repo_names %s', { + 'acl_repo_name': acl_repo_name, + 'vcs_repo_name': vcs_repo_name, + 'url_repo_name': url_repo_name, + }) + log.debug('pull_request %s', pr_id) + # check for type, presence in database and on filesystem if not vcs_handler.is_valid_and_existing_repo( - repo_name, vcs_handler.basepath, vcs_handler.SCM): + acl_repo_name, vcs_handler.basepath, vcs_handler.SCM): return HTTPNotFound()(environ, start_response) # TODO: johbo: Needed for the Pyro4 backend and Mercurial only. # Remove once we fully switched to the HTTP backend. - environ['REPO_NAME'] = repo_name + environ['REPO_NAME'] = url_repo_name # register repo_name and it's config back to the handler - vcs_handler.repo_name = repo_name - vcs_handler.repo_vcs_config = self.vcs_config(repo_name) + vcs_handler.acl_repo_name = acl_repo_name + vcs_handler.url_repo_name = url_repo_name + vcs_handler.vcs_repo_name = vcs_repo_name + vcs_handler.pr_id = pr_id + vcs_handler.repo_vcs_config = self.vcs_config(acl_repo_name) vcs_handler = self.wrap_in_gzip_if_enabled( vcs_handler, self.config) diff --git a/rhodecode/tests/lib/middleware/test_simplevcs.py b/rhodecode/tests/lib/middleware/test_simplevcs.py --- a/rhodecode/tests/lib/middleware/test_simplevcs.py +++ b/rhodecode/tests/lib/middleware/test_simplevcs.py @@ -44,7 +44,9 @@ class StubVCSController(simplevcs.Simple def __init__(self, *args, **kwargs): super(StubVCSController, self).__init__(*args, **kwargs) - self.repo_name = HG_REPO + self.acl_repo_name = HG_REPO + self.url_repo_name = HG_REPO + self.vcs_repo_name = HG_REPO def _get_repository_name(self, environ): return HG_REPO