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 @@ -201,14 +201,11 @@ class SimpleVCS(object): # Only proceed if we got a pull request and if acl repo name from # URL equals the target repo name of the pull request. - if pull_request and \ - (acl_repo_name == pull_request.target_repo.repo_name): - repo_id = pull_request.target_repo.repo_id + if pull_request and (acl_repo_name == pull_request.target_repo.repo_name): + # Get file system path to shadow repository. workspace_id = PullRequestModel()._workspace_id(pull_request) - target_vcs = pull_request.target_repo.scm_instance() - vcs_repo_name = target_vcs._get_shadow_repository_path( - repo_id, workspace_id) + vcs_repo_name = pull_request.target_repo.get_shadow_repository_path(workspace_id) # Store names for later usage. self.vcs_repo_name = vcs_repo_name diff --git a/rhodecode/lib/vcs/backends/base.py b/rhodecode/lib/vcs/backends/base.py --- a/rhodecode/lib/vcs/backends/base.py +++ b/rhodecode/lib/vcs/backends/base.py @@ -645,24 +645,26 @@ class BaseRepository(object): """ raise NotImplementedError - def _get_legacy_shadow_repository_path(self, workspace_id): + @classmethod + def _get_legacy_shadow_repository_path(cls, repo_path, workspace_id): """ Legacy version that was used before. We still need it for backward compat """ return os.path.join( - os.path.dirname(self.path), - '.__shadow_%s_%s' % (os.path.basename(self.path), workspace_id)) + os.path.dirname(repo_path), + '.__shadow_%s_%s' % (os.path.basename(repo_path), workspace_id)) - def _get_shadow_repository_path(self, repo_id, workspace_id): + @classmethod + def _get_shadow_repository_path(cls, repo_path, repo_id, workspace_id): # The name of the shadow repository must start with '.', so it is # skipped by 'rhodecode.lib.utils.get_filesystem_repos'. - legacy_repository_path = self._get_legacy_shadow_repository_path(workspace_id) + legacy_repository_path = cls._get_legacy_shadow_repository_path(repo_path, workspace_id) if os.path.exists(legacy_repository_path): return legacy_repository_path else: return os.path.join( - os.path.dirname(self.path), + os.path.dirname(repo_path), '.__shadow_repo_%s_%s' % (repo_id, workspace_id)) def cleanup_merge_workspace(self, repo_id, workspace_id): @@ -674,7 +676,8 @@ class BaseRepository(object): :param workspace_id: `workspace_id` unique identifier. """ - shadow_repository_path = self._get_shadow_repository_path(repo_id, workspace_id) + shadow_repository_path = self._get_shadow_repository_path( + self.path, repo_id, workspace_id) shadow_repository_path_del = '{}.{}.delete'.format( shadow_repository_path, time.time()) diff --git a/rhodecode/lib/vcs/backends/git/repository.py b/rhodecode/lib/vcs/backends/git/repository.py --- a/rhodecode/lib/vcs/backends/git/repository.py +++ b/rhodecode/lib/vcs/backends/git/repository.py @@ -892,7 +892,7 @@ class GitRepository(BaseRepository): def _maybe_prepare_merge_workspace( self, repo_id, workspace_id, target_ref, source_ref): shadow_repository_path = self._get_shadow_repository_path( - repo_id, workspace_id) + self.path, repo_id, workspace_id) if not os.path.exists(shadow_repository_path): self._local_clone( shadow_repository_path, target_ref.name, source_ref.name) diff --git a/rhodecode/lib/vcs/backends/hg/repository.py b/rhodecode/lib/vcs/backends/hg/repository.py --- a/rhodecode/lib/vcs/backends/hg/repository.py +++ b/rhodecode/lib/vcs/backends/hg/repository.py @@ -704,7 +704,7 @@ class MercurialRepository(BaseRepository def _maybe_prepare_merge_workspace( self, repo_id, workspace_id, unused_target_ref, unused_source_ref): shadow_repository_path = self._get_shadow_repository_path( - repo_id, workspace_id) + self.path, repo_id, workspace_id) if not os.path.exists(shadow_repository_path): self._local_clone(shadow_repository_path) log.debug( diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -2505,6 +2505,12 @@ class Repository(Base, BaseModel): repo.count() # cache rebuild return repo + def get_shadow_repository_path(self, workspace_id): + from rhodecode.lib.vcs.backends.base import BaseRepository + shadow_repo_path = BaseRepository._get_shadow_repository_path( + self.repo_full_path, self.repo_id, workspace_id) + return shadow_repo_path + def __json__(self): return {'landing_rev': self.landing_rev} @@ -4209,10 +4215,9 @@ class PullRequest(Base, _PullRequestBase def get_shadow_repo(self): workspace_id = self.workspace_id - vcs_obj = self.target_repo.scm_instance() - shadow_repository_path = vcs_obj._get_shadow_repository_path( - self.target_repo.repo_id, workspace_id) + shadow_repository_path = self.target_repo.get_shadow_repository_path(workspace_id) if os.path.isdir(shadow_repository_path): + vcs_obj = self.target_repo.scm_instance() return vcs_obj.get_shadow_instance(shadow_repository_path) 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 @@ -333,9 +333,7 @@ class TestShadowRepoExposure(object): # Get file system path to shadow repo for assertions. workspace_id = PullRequestModel()._workspace_id(pull_request) - target_vcs = pull_request.target_repo.scm_instance() - vcs_repo_name = target_vcs._get_shadow_repository_path( - pull_request.target_repo.repo_id, workspace_id) + vcs_repo_name = pull_request.target_repo.get_shadow_repository_path(workspace_id) assert controller.vcs_repo_name == vcs_repo_name assert controller.url_repo_name == shadow_url