diff options
author | Jack Neus <jackneus@google.com> | 2021-09-21 22:23:55 +0000 |
---|---|---|
committer | Jack Neus <jackneus@google.com> | 2021-09-23 21:17:38 +0000 |
commit | a84f43a0065e7af2a30fd6b99bf3f13efcc7961c (patch) | |
tree | 65f6fd8a7acbb216cf7032086072ac9d7947a176 /manifest_xml.py | |
parent | 0468feac395f6b1fc310387db606cf6b6ed53f33 (diff) | |
download | git-repo-a84f43a0065e7af2a30fd6b99bf3f13efcc7961c.tar.gz |
manifest: make repo-hooks more robust wrt element ordering
Currently, repo will fail to sync to a manifest if the definition
of the repo-hooks project comes after the repo-hooks element.
BUG=none
TEST=new test, run_tests
Change-Id: I0bf85625173492af6c6404d4b67543e96e670562
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/318520
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Jack Neus <jackneus@google.com>
Diffstat (limited to 'manifest_xml.py')
-rw-r--r-- | manifest_xml.py | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index 55ad6c08..7099d5fe 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -852,6 +852,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
852 | for subproject in project.subprojects: | 852 | for subproject in project.subprojects: |
853 | recursively_add_projects(subproject) | 853 | recursively_add_projects(subproject) |
854 | 854 | ||
855 | repo_hooks_project = None | ||
856 | enabled_repo_hooks = None | ||
855 | for node in itertools.chain(*node_list): | 857 | for node in itertools.chain(*node_list): |
856 | if node.nodeName == 'project': | 858 | if node.nodeName == 'project': |
857 | project = self._ParseProject(node) | 859 | project = self._ParseProject(node) |
@@ -886,32 +888,15 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
886 | if remote: | 888 | if remote: |
887 | p.remote = remote.ToRemoteSpec(name) | 889 | p.remote = remote.ToRemoteSpec(name) |
888 | if node.nodeName == 'repo-hooks': | 890 | if node.nodeName == 'repo-hooks': |
889 | # Get the name of the project and the (space-separated) list of enabled. | ||
890 | repo_hooks_project = self._reqatt(node, 'in-project') | ||
891 | enabled_repo_hooks = self._ParseList(self._reqatt(node, 'enabled-list')) | ||
892 | |||
893 | # Only one project can be the hooks project | 891 | # Only one project can be the hooks project |
894 | if self._repo_hooks_project is not None: | 892 | if repo_hooks_project is not None: |
895 | raise ManifestParseError( | 893 | raise ManifestParseError( |
896 | 'duplicate repo-hooks in %s' % | 894 | 'duplicate repo-hooks in %s' % |
897 | (self.manifestFile)) | 895 | (self.manifestFile)) |
898 | 896 | ||
899 | # Store a reference to the Project. | 897 | # Get the name of the project and the (space-separated) list of enabled. |
900 | try: | 898 | repo_hooks_project = self._reqatt(node, 'in-project') |
901 | repo_hooks_projects = self._projects[repo_hooks_project] | 899 | enabled_repo_hooks = self._ParseList(self._reqatt(node, 'enabled-list')) |
902 | except KeyError: | ||
903 | raise ManifestParseError( | ||
904 | 'project %s not found for repo-hooks' % | ||
905 | (repo_hooks_project)) | ||
906 | |||
907 | if len(repo_hooks_projects) != 1: | ||
908 | raise ManifestParseError( | ||
909 | 'internal error parsing repo-hooks in %s' % | ||
910 | (self.manifestFile)) | ||
911 | self._repo_hooks_project = repo_hooks_projects[0] | ||
912 | |||
913 | # Store the enabled hooks in the Project object. | ||
914 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks | ||
915 | if node.nodeName == 'superproject': | 900 | if node.nodeName == 'superproject': |
916 | name = self._reqatt(node, 'name') | 901 | name = self._reqatt(node, 'name') |
917 | # There can only be one superproject. | 902 | # There can only be one superproject. |
@@ -944,12 +929,30 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
944 | 929 | ||
945 | # If the manifest removes the hooks project, treat it as if it deleted | 930 | # If the manifest removes the hooks project, treat it as if it deleted |
946 | # the repo-hooks element too. | 931 | # the repo-hooks element too. |
947 | if self._repo_hooks_project and (self._repo_hooks_project.name == name): | 932 | if repo_hooks_project == name: |
948 | self._repo_hooks_project = None | 933 | repo_hooks_project = None |
949 | elif not XmlBool(node, 'optional', False): | 934 | elif not XmlBool(node, 'optional', False): |
950 | raise ManifestParseError('remove-project element specifies non-existent ' | 935 | raise ManifestParseError('remove-project element specifies non-existent ' |
951 | 'project: %s' % name) | 936 | 'project: %s' % name) |
952 | 937 | ||
938 | # Store repo hooks project information. | ||
939 | if repo_hooks_project: | ||
940 | # Store a reference to the Project. | ||
941 | try: | ||
942 | repo_hooks_projects = self._projects[repo_hooks_project] | ||
943 | except KeyError: | ||
944 | raise ManifestParseError( | ||
945 | 'project %s not found for repo-hooks' % | ||
946 | (repo_hooks_project)) | ||
947 | |||
948 | if len(repo_hooks_projects) != 1: | ||
949 | raise ManifestParseError( | ||
950 | 'internal error parsing repo-hooks in %s' % | ||
951 | (self.manifestFile)) | ||
952 | self._repo_hooks_project = repo_hooks_projects[0] | ||
953 | # Store the enabled hooks in the Project object. | ||
954 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks | ||
955 | |||
953 | def _AddMetaProjectMirror(self, m): | 956 | def _AddMetaProjectMirror(self, m): |
954 | name = None | 957 | name = None |
955 | m_url = m.GetRemote(m.remote.name).url | 958 | m_url = m.GetRemote(m.remote.name).url |