##// END OF EJS Templates
vcs: Get shadow repository file system path by using already existing functions....
Martin Bornhold -
r892:54fc3d2c default
parent child Browse files
Show More
@@ -107,25 +107,46 b' class SimpleVCS(object):'
107 107
108 108 def set_repo_names(self, environ):
109 109 """
110 This will populate the attributes acl_repo_name, url_repo_name and
111 vcs_repo_name on the current instance.
110 This will populate the attributes acl_repo_name, url_repo_name,
111 vcs_repo_name and pr_id on the current instance.
112 112 """
113 113 # TODO: martinb: Move to class or module scope.
114 # TODO: martinb: Check if we have to use re.UNICODE.
115 # TODO: martinb: Check which chars are allowed for repo/group names.
116 # These chars are excluded: '`?=[]\;\'"<>,/~!@#$%^&*()+{}|: '
117 # Code from: rhodecode/lib/utils.py:repo_name_slug()
114 118 pr_regex = re.compile(
115 '(?P<base_name>(?:[\w-]+)(?:/[\w-]+)*)/'
116 '(?P<repo_name>[\w-]+)'
117 '/pull-request/(?P<pr_id>\d+)/repository')
119 '(?P<base_name>(?:[\w-]+)(?:/[\w-]+)*)/' # repo groups
120 '(?P<repo_name>[\w-]+)' # target repo name
121 '/pull-request/(?P<pr_id>\d+)/repository') # pr suffix
118 122
123 # Get url repo name from environment.
119 124 self.url_repo_name = self._get_repository_name(environ)
120 match = pr_regex.match(self.url_repo_name)
121 125
126 # Check if this is a request to a shadow repository. In case of a
127 # shadow repo set vcs_repo_name to the file system path pointing to the
128 # shadow repo. And set acl_repo_name to the pull request target repo
129 # because we use the target repo for permission checks. Otherwise all
130 # names are equal.
131 match = pr_regex.match(self.url_repo_name)
122 132 if match:
133 # Get pull request instance.
123 134 match_dict = match.groupdict()
124 self.acl_repo_name = '{base_name}/{repo_name}'.format(**match_dict)
125 self.vcs_repo_name = '{base_name}/.__shadow_{repo_name}_pr-{pr_id}'.format(
126 **match_dict)
127 self.pr_id = match_dict['pr_id']
135 pr_id = match_dict['pr_id']
136 pull_request = PullRequest.get(pr_id)
137
138 # Get file system path to shadow repository.
139 workspace_id = PullRequestModel()._workspace_id(pull_request)
140 target_vcs = pull_request.target_repo.scm_instance()
141 vcs_repo_name = target_vcs._get_shadow_repository_path(
142 workspace_id)
143
144 # Store names for later usage.
145 self.pr_id = pr_id
146 self.vcs_repo_name = vcs_repo_name
147 self.acl_repo_name = pull_request.target_repo.repo_name
128 148 else:
149 # All names are equal for normal (non shadow) repositories.
129 150 self.acl_repo_name = self.url_repo_name
130 151 self.vcs_repo_name = self.url_repo_name
131 152 self.pr_id = None
General Comments 0
You need to be logged in to leave comments. Login now