##// END OF EJS Templates
shadow-repos: skip init of full repo to generate shadow repo path.
marcink -
r3931:2a9f3cf9 default
parent child Browse files
Show More
@@ -201,14 +201,11 b' class SimpleVCS(object):'
201 201
202 202 # Only proceed if we got a pull request and if acl repo name from
203 203 # URL equals the target repo name of the pull request.
204 if pull_request and \
205 (acl_repo_name == pull_request.target_repo.repo_name):
206 repo_id = pull_request.target_repo.repo_id
204 if pull_request and (acl_repo_name == pull_request.target_repo.repo_name):
205
207 206 # Get file system path to shadow repository.
208 207 workspace_id = PullRequestModel()._workspace_id(pull_request)
209 target_vcs = pull_request.target_repo.scm_instance()
210 vcs_repo_name = target_vcs._get_shadow_repository_path(
211 repo_id, workspace_id)
208 vcs_repo_name = pull_request.target_repo.get_shadow_repository_path(workspace_id)
212 209
213 210 # Store names for later usage.
214 211 self.vcs_repo_name = vcs_repo_name
@@ -645,24 +645,26 b' class BaseRepository(object):'
645 645 """
646 646 raise NotImplementedError
647 647
648 def _get_legacy_shadow_repository_path(self, workspace_id):
648 @classmethod
649 def _get_legacy_shadow_repository_path(cls, repo_path, workspace_id):
649 650 """
650 651 Legacy version that was used before. We still need it for
651 652 backward compat
652 653 """
653 654 return os.path.join(
654 os.path.dirname(self.path),
655 '.__shadow_%s_%s' % (os.path.basename(self.path), workspace_id))
655 os.path.dirname(repo_path),
656 '.__shadow_%s_%s' % (os.path.basename(repo_path), workspace_id))
656 657
657 def _get_shadow_repository_path(self, repo_id, workspace_id):
658 @classmethod
659 def _get_shadow_repository_path(cls, repo_path, repo_id, workspace_id):
658 660 # The name of the shadow repository must start with '.', so it is
659 661 # skipped by 'rhodecode.lib.utils.get_filesystem_repos'.
660 legacy_repository_path = self._get_legacy_shadow_repository_path(workspace_id)
662 legacy_repository_path = cls._get_legacy_shadow_repository_path(repo_path, workspace_id)
661 663 if os.path.exists(legacy_repository_path):
662 664 return legacy_repository_path
663 665 else:
664 666 return os.path.join(
665 os.path.dirname(self.path),
667 os.path.dirname(repo_path),
666 668 '.__shadow_repo_%s_%s' % (repo_id, workspace_id))
667 669
668 670 def cleanup_merge_workspace(self, repo_id, workspace_id):
@@ -674,7 +676,8 b' class BaseRepository(object):'
674 676
675 677 :param workspace_id: `workspace_id` unique identifier.
676 678 """
677 shadow_repository_path = self._get_shadow_repository_path(repo_id, workspace_id)
679 shadow_repository_path = self._get_shadow_repository_path(
680 self.path, repo_id, workspace_id)
678 681 shadow_repository_path_del = '{}.{}.delete'.format(
679 682 shadow_repository_path, time.time())
680 683
@@ -892,7 +892,7 b' class GitRepository(BaseRepository):'
892 892 def _maybe_prepare_merge_workspace(
893 893 self, repo_id, workspace_id, target_ref, source_ref):
894 894 shadow_repository_path = self._get_shadow_repository_path(
895 repo_id, workspace_id)
895 self.path, repo_id, workspace_id)
896 896 if not os.path.exists(shadow_repository_path):
897 897 self._local_clone(
898 898 shadow_repository_path, target_ref.name, source_ref.name)
@@ -704,7 +704,7 b' class MercurialRepository(BaseRepository'
704 704 def _maybe_prepare_merge_workspace(
705 705 self, repo_id, workspace_id, unused_target_ref, unused_source_ref):
706 706 shadow_repository_path = self._get_shadow_repository_path(
707 repo_id, workspace_id)
707 self.path, repo_id, workspace_id)
708 708 if not os.path.exists(shadow_repository_path):
709 709 self._local_clone(shadow_repository_path)
710 710 log.debug(
@@ -2505,6 +2505,12 b' class Repository(Base, BaseModel):'
2505 2505 repo.count() # cache rebuild
2506 2506 return repo
2507 2507
2508 def get_shadow_repository_path(self, workspace_id):
2509 from rhodecode.lib.vcs.backends.base import BaseRepository
2510 shadow_repo_path = BaseRepository._get_shadow_repository_path(
2511 self.repo_full_path, self.repo_id, workspace_id)
2512 return shadow_repo_path
2513
2508 2514 def __json__(self):
2509 2515 return {'landing_rev': self.landing_rev}
2510 2516
@@ -4209,10 +4215,9 b' class PullRequest(Base, _PullRequestBase'
4209 4215
4210 4216 def get_shadow_repo(self):
4211 4217 workspace_id = self.workspace_id
4218 shadow_repository_path = self.target_repo.get_shadow_repository_path(workspace_id)
4219 if os.path.isdir(shadow_repository_path):
4212 4220 vcs_obj = self.target_repo.scm_instance()
4213 shadow_repository_path = vcs_obj._get_shadow_repository_path(
4214 self.target_repo.repo_id, workspace_id)
4215 if os.path.isdir(shadow_repository_path):
4216 4221 return vcs_obj.get_shadow_instance(shadow_repository_path)
4217 4222
4218 4223
@@ -333,9 +333,7 b' class TestShadowRepoExposure(object):'
333 333
334 334 # Get file system path to shadow repo for assertions.
335 335 workspace_id = PullRequestModel()._workspace_id(pull_request)
336 target_vcs = pull_request.target_repo.scm_instance()
337 vcs_repo_name = target_vcs._get_shadow_repository_path(
338 pull_request.target_repo.repo_id, workspace_id)
336 vcs_repo_name = pull_request.target_repo.get_shadow_repository_path(workspace_id)
339 337
340 338 assert controller.vcs_repo_name == vcs_repo_name
341 339 assert controller.url_repo_name == shadow_url
General Comments 0
You need to be logged in to leave comments. Login now