diff options
Diffstat (limited to 'manifest_xml.py')
| -rw-r--r-- | manifest_xml.py | 68 |
1 files changed, 49 insertions, 19 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index 457d5ab0..c5f3bcc9 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
| @@ -215,8 +215,9 @@ class XmlManifest(object): | |||
| 215 | root.appendChild(doc.createTextNode('')) | 215 | root.appendChild(doc.createTextNode('')) |
| 216 | 216 | ||
| 217 | def output_projects(parent, parent_node, projects): | 217 | def output_projects(parent, parent_node, projects): |
| 218 | for p in projects: | 218 | for project_name in projects: |
| 219 | output_project(parent, parent_node, self.projects[p]) | 219 | for project in self._projects[project_name]: |
| 220 | output_project(parent, parent_node, project) | ||
| 220 | 221 | ||
| 221 | def output_project(parent, parent_node, p): | 222 | def output_project(parent, parent_node, p): |
| 222 | if not p.MatchesGroups(groups): | 223 | if not p.MatchesGroups(groups): |
| @@ -277,13 +278,11 @@ class XmlManifest(object): | |||
| 277 | e.setAttribute('sync-s', 'true') | 278 | e.setAttribute('sync-s', 'true') |
| 278 | 279 | ||
| 279 | if p.subprojects: | 280 | if p.subprojects: |
| 280 | sort_projects = list(sorted([subp.name for subp in p.subprojects])) | 281 | subprojects = set(subp.name for subp in p.subprojects) |
| 281 | output_projects(p, e, sort_projects) | 282 | output_projects(p, e, list(sorted(subprojects))) |
| 282 | 283 | ||
| 283 | sort_projects = list(sorted([key for key, value in self.projects.items() | 284 | projects = set(p.name for p in self._paths.values() if not p.parent) |
| 284 | if not value.parent])) | 285 | output_projects(None, root, list(sorted(projects))) |
| 285 | sort_projects.sort() | ||
| 286 | output_projects(None, root, sort_projects) | ||
| 287 | 286 | ||
| 288 | if self._repo_hooks_project: | 287 | if self._repo_hooks_project: |
| 289 | root.appendChild(doc.createTextNode('')) | 288 | root.appendChild(doc.createTextNode('')) |
| @@ -296,9 +295,14 @@ class XmlManifest(object): | |||
| 296 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') | 295 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') |
| 297 | 296 | ||
| 298 | @property | 297 | @property |
| 298 | def paths(self): | ||
| 299 | self._Load() | ||
| 300 | return self._paths | ||
| 301 | |||
| 302 | @property | ||
| 299 | def projects(self): | 303 | def projects(self): |
| 300 | self._Load() | 304 | self._Load() |
| 301 | return self._projects | 305 | return self._paths.values() |
| 302 | 306 | ||
| 303 | @property | 307 | @property |
| 304 | def remotes(self): | 308 | def remotes(self): |
| @@ -329,9 +333,14 @@ class XmlManifest(object): | |||
| 329 | def IsMirror(self): | 333 | def IsMirror(self): |
| 330 | return self.manifestProject.config.GetBoolean('repo.mirror') | 334 | return self.manifestProject.config.GetBoolean('repo.mirror') |
| 331 | 335 | ||
| 336 | @property | ||
| 337 | def IsArchive(self): | ||
| 338 | return self.manifestProject.config.GetBoolean('repo.archive') | ||
| 339 | |||
| 332 | def _Unload(self): | 340 | def _Unload(self): |
| 333 | self._loaded = False | 341 | self._loaded = False |
| 334 | self._projects = {} | 342 | self._projects = {} |
| 343 | self._paths = {} | ||
| 335 | self._remotes = {} | 344 | self._remotes = {} |
| 336 | self._default = None | 345 | self._default = None |
| 337 | self._repo_hooks_project = None | 346 | self._repo_hooks_project = None |
| @@ -463,11 +472,17 @@ class XmlManifest(object): | |||
| 463 | self._manifest_server = url | 472 | self._manifest_server = url |
| 464 | 473 | ||
| 465 | def recursively_add_projects(project): | 474 | def recursively_add_projects(project): |
| 466 | if self._projects.get(project.name): | 475 | projects = self._projects.setdefault(project.name, []) |
| 476 | if project.relpath is None: | ||
| 467 | raise ManifestParseError( | 477 | raise ManifestParseError( |
| 468 | 'duplicate project %s in %s' % | 478 | 'missing path for %s in %s' % |
| 469 | (project.name, self.manifestFile)) | 479 | (project.name, self.manifestFile)) |
| 470 | self._projects[project.name] = project | 480 | if project.relpath in self._paths: |
| 481 | raise ManifestParseError( | ||
| 482 | 'duplicate path %s in %s' % | ||
| 483 | (project.relpath, self.manifestFile)) | ||
| 484 | self._paths[project.relpath] = project | ||
| 485 | projects.append(project) | ||
| 471 | for subproject in project.subprojects: | 486 | for subproject in project.subprojects: |
| 472 | recursively_add_projects(subproject) | 487 | recursively_add_projects(subproject) |
| 473 | 488 | ||
| @@ -488,12 +503,18 @@ class XmlManifest(object): | |||
| 488 | 503 | ||
| 489 | # Store a reference to the Project. | 504 | # Store a reference to the Project. |
| 490 | try: | 505 | try: |
| 491 | self._repo_hooks_project = self._projects[repo_hooks_project] | 506 | repo_hooks_projects = self._projects[repo_hooks_project] |
| 492 | except KeyError: | 507 | except KeyError: |
| 493 | raise ManifestParseError( | 508 | raise ManifestParseError( |
| 494 | 'project %s not found for repo-hooks' % | 509 | 'project %s not found for repo-hooks' % |
| 495 | (repo_hooks_project)) | 510 | (repo_hooks_project)) |
| 496 | 511 | ||
| 512 | if len(repo_hooks_projects) != 1: | ||
| 513 | raise ManifestParseError( | ||
| 514 | 'internal error parsing repo-hooks in %s' % | ||
| 515 | (self.manifestFile)) | ||
| 516 | self._repo_hooks_project = repo_hooks_projects[0] | ||
| 517 | |||
| 497 | # Store the enabled hooks in the Project object. | 518 | # Store the enabled hooks in the Project object. |
| 498 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks | 519 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks |
| 499 | if node.nodeName == 'remove-project': | 520 | if node.nodeName == 'remove-project': |
| @@ -540,11 +561,12 @@ class XmlManifest(object): | |||
| 540 | name = name, | 561 | name = name, |
| 541 | remote = remote.ToRemoteSpec(name), | 562 | remote = remote.ToRemoteSpec(name), |
| 542 | gitdir = gitdir, | 563 | gitdir = gitdir, |
| 564 | objdir = gitdir, | ||
| 543 | worktree = None, | 565 | worktree = None, |
| 544 | relpath = None, | 566 | relpath = None, |
| 545 | revisionExpr = m.revisionExpr, | 567 | revisionExpr = m.revisionExpr, |
| 546 | revisionId = None) | 568 | revisionId = None) |
| 547 | self._projects[project.name] = project | 569 | self._projects[project.name] = [project] |
| 548 | 570 | ||
| 549 | def _ParseRemote(self, node): | 571 | def _ParseRemote(self, node): |
| 550 | """ | 572 | """ |
| @@ -704,9 +726,10 @@ class XmlManifest(object): | |||
| 704 | groups = [x for x in re.split(r'[,\s]+', groups) if x] | 726 | groups = [x for x in re.split(r'[,\s]+', groups) if x] |
| 705 | 727 | ||
| 706 | if parent is None: | 728 | if parent is None: |
| 707 | relpath, worktree, gitdir = self.GetProjectPaths(name, path) | 729 | relpath, worktree, gitdir, objdir = self.GetProjectPaths(name, path) |
| 708 | else: | 730 | else: |
| 709 | relpath, worktree, gitdir = self.GetSubprojectPaths(parent, path) | 731 | relpath, worktree, gitdir, objdir = \ |
| 732 | self.GetSubprojectPaths(parent, name, path) | ||
| 710 | 733 | ||
| 711 | default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath] | 734 | default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath] |
| 712 | groups.extend(set(default_groups).difference(groups)) | 735 | groups.extend(set(default_groups).difference(groups)) |
| @@ -719,6 +742,7 @@ class XmlManifest(object): | |||
| 719 | name = name, | 742 | name = name, |
| 720 | remote = remote.ToRemoteSpec(name), | 743 | remote = remote.ToRemoteSpec(name), |
| 721 | gitdir = gitdir, | 744 | gitdir = gitdir, |
| 745 | objdir = objdir, | ||
| 722 | worktree = worktree, | 746 | worktree = worktree, |
| 723 | relpath = relpath, | 747 | relpath = relpath, |
| 724 | revisionExpr = revisionExpr, | 748 | revisionExpr = revisionExpr, |
| @@ -747,10 +771,15 @@ class XmlManifest(object): | |||
| 747 | if self.IsMirror: | 771 | if self.IsMirror: |
| 748 | worktree = None | 772 | worktree = None |
| 749 | gitdir = os.path.join(self.topdir, '%s.git' % name) | 773 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 774 | objdir = gitdir | ||
| 750 | else: | 775 | else: |
| 751 | worktree = os.path.join(self.topdir, path).replace('\\', '/') | 776 | worktree = os.path.join(self.topdir, path).replace('\\', '/') |
| 752 | gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path) | 777 | gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path) |
| 753 | return relpath, worktree, gitdir | 778 | objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name) |
| 779 | return relpath, worktree, gitdir, objdir | ||
| 780 | |||
| 781 | def GetProjectsWithName(self, name): | ||
| 782 | return self._projects.get(name, []) | ||
| 754 | 783 | ||
| 755 | def GetSubprojectName(self, parent, submodule_path): | 784 | def GetSubprojectName(self, parent, submodule_path): |
| 756 | return os.path.join(parent.name, submodule_path) | 785 | return os.path.join(parent.name, submodule_path) |
| @@ -761,14 +790,15 @@ class XmlManifest(object): | |||
| 761 | def _UnjoinRelpath(self, parent_relpath, relpath): | 790 | def _UnjoinRelpath(self, parent_relpath, relpath): |
| 762 | return os.path.relpath(relpath, parent_relpath) | 791 | return os.path.relpath(relpath, parent_relpath) |
| 763 | 792 | ||
| 764 | def GetSubprojectPaths(self, parent, path): | 793 | def GetSubprojectPaths(self, parent, name, path): |
| 765 | relpath = self._JoinRelpath(parent.relpath, path) | 794 | relpath = self._JoinRelpath(parent.relpath, path) |
| 766 | gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path) | 795 | gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path) |
| 796 | objdir = os.path.join(parent.gitdir, 'subproject-objects', '%s.git' % name) | ||
| 767 | if self.IsMirror: | 797 | if self.IsMirror: |
| 768 | worktree = None | 798 | worktree = None |
| 769 | else: | 799 | else: |
| 770 | worktree = os.path.join(parent.worktree, path).replace('\\', '/') | 800 | worktree = os.path.join(parent.worktree, path).replace('\\', '/') |
| 771 | return relpath, worktree, gitdir | 801 | return relpath, worktree, gitdir, objdir |
| 772 | 802 | ||
| 773 | def _ParseCopyFile(self, project, node): | 803 | def _ParseCopyFile(self, project, node): |
| 774 | src = self._reqatt(node, 'src') | 804 | src = self._reqatt(node, 'src') |
