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