Freeze regex projects

Add a copy method to ProjectConfig objects so that we can return
a frozen ProjectConfig from the ProjectParser, but then make an
unfrozen copy so that we can change its name (and then freeze the
copy) when treating it as a regex project.

Change-Id: I2f39d9a33b9282e44daf5e9a0af3fd35e87e844e
This commit is contained in:
James E. Blair 2018-04-30 13:13:46 -07:00
parent 20d3327884
commit b9ba3a9aa1
2 changed files with 11 additions and 7 deletions

View File

@ -930,8 +930,6 @@ class ProjectParser(object):
# of the project where it is defined.
project_name = (conf['_source_context'].project.canonical_name)
# regex matched projects need to be validatd later
regex = False
if project_name.startswith('^'):
# regex matching is designed to match other projects so disallow
# in untrusted contexts
@ -940,7 +938,6 @@ class ProjectParser(object):
# Parse the project as a template since they're mostly the
# same.
regex = True
project_config = self.pcontext.project_template_parser. \
fromYaml(conf, validate=False, freeze=False)
@ -978,9 +975,7 @@ class ProjectParser(object):
default_branch = conf.get('default-branch', 'master')
project_config.default_branch = default_branch
# we need to freeze regex projects later
if not regex:
project_config.freeze()
project_config.freeze()
return project_config
@ -1739,7 +1734,7 @@ class TenantParser(object):
for config_project in config_projects:
# we just override the project name here so a simple copy
# should be enough
conf = copy.copy(config_project)
conf = config_project.copy()
name = project.canonical_name
conf.name = name
conf.freeze()

View File

@ -2511,6 +2511,15 @@ class ProjectConfig(ConfigObject):
self.pipelines = {}
self.branch_matcher = None
def copy(self):
r = self.__class__(self.name)
r.source_context = self.source_context
r.start_mark = self.start_mark
r.templates = self.templates
r.pipelines = self.pipelines
r.branch_matcher = self.branch_matcher
return r
def addImpliedBranchMatcher(self, branch):
self.branch_matcher = change_matcher.ImpliedBranchMatcher(branch)