diff options
author | Shawn O. Pearce <sop@google.com> | 2012-10-26 12:30:38 -0700 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-10-26 12:30:38 -0700 |
commit | de7eae482664d4bda61238b6adb679b3b92535d2 (patch) | |
tree | fab047f944470100c621b39da83bd80991f7bdbf /manifest_xml.py | |
parent | 2fe99e8820a84f545ad45d53921dc94b8bc9d4f3 (diff) | |
parent | cd81dd6403fc8dbe6ec5920c517d9083902c3c1f (diff) | |
download | git-repo-de7eae482664d4bda61238b6adb679b3b92535d2.tar.gz |
Merge "Revert "Represent git-submodule as nested projects""
Diffstat (limited to 'manifest_xml.py')
-rw-r--r-- | manifest_xml.py | 108 |
1 files changed, 26 insertions, 82 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index 11e4ee54..dd163bed 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -180,25 +180,20 @@ class XmlManifest(object): | |||
180 | root.appendChild(e) | 180 | root.appendChild(e) |
181 | root.appendChild(doc.createTextNode('')) | 181 | root.appendChild(doc.createTextNode('')) |
182 | 182 | ||
183 | def output_projects(parent, parent_node, projects): | 183 | sort_projects = list(self.projects.keys()) |
184 | for p in projects: | 184 | sort_projects.sort() |
185 | output_project(parent, parent_node, self.projects[p]) | ||
186 | 185 | ||
187 | def output_project(parent, parent_node, p): | 186 | for p in sort_projects: |
188 | if not p.MatchesGroups(groups): | 187 | p = self.projects[p] |
189 | return | ||
190 | 188 | ||
191 | name = p.name | 189 | if not p.MatchesGroups(groups): |
192 | relpath = p.relpath | 190 | continue |
193 | if parent: | ||
194 | name = self._UnjoinName(parent.name, name) | ||
195 | relpath = self._UnjoinRelpath(parent.relpath, relpath) | ||
196 | 191 | ||
197 | e = doc.createElement('project') | 192 | e = doc.createElement('project') |
198 | parent_node.appendChild(e) | 193 | root.appendChild(e) |
199 | e.setAttribute('name', name) | 194 | e.setAttribute('name', p.name) |
200 | if relpath != name: | 195 | if p.relpath != p.name: |
201 | e.setAttribute('path', relpath) | 196 | e.setAttribute('path', p.relpath) |
202 | if not d.remote or p.remote.name != d.remote.name: | 197 | if not d.remote or p.remote.name != d.remote.name: |
203 | e.setAttribute('remote', p.remote.name) | 198 | e.setAttribute('remote', p.remote.name) |
204 | if peg_rev: | 199 | if peg_rev: |
@@ -236,16 +231,6 @@ class XmlManifest(object): | |||
236 | if p.sync_c: | 231 | if p.sync_c: |
237 | e.setAttribute('sync-c', 'true') | 232 | e.setAttribute('sync-c', 'true') |
238 | 233 | ||
239 | if p.subprojects: | ||
240 | sort_projects = [subp.name for subp in p.subprojects] | ||
241 | sort_projects.sort() | ||
242 | output_projects(p, e, sort_projects) | ||
243 | |||
244 | sort_projects = [key for key in self.projects.keys() | ||
245 | if not self.projects[key].parent] | ||
246 | sort_projects.sort() | ||
247 | output_projects(None, root, sort_projects) | ||
248 | |||
249 | if self._repo_hooks_project: | 234 | if self._repo_hooks_project: |
250 | root.appendChild(doc.createTextNode('')) | 235 | root.appendChild(doc.createTextNode('')) |
251 | e = doc.createElement('repo-hooks') | 236 | e = doc.createElement('repo-hooks') |
@@ -398,15 +383,11 @@ class XmlManifest(object): | |||
398 | for node in itertools.chain(*node_list): | 383 | for node in itertools.chain(*node_list): |
399 | if node.nodeName == 'project': | 384 | if node.nodeName == 'project': |
400 | project = self._ParseProject(node) | 385 | project = self._ParseProject(node) |
401 | def recursively_add_projects(project): | 386 | if self._projects.get(project.name): |
402 | if self._projects.get(project.name): | 387 | raise ManifestParseError( |
403 | raise ManifestParseError( | 388 | 'duplicate project %s in %s' % |
404 | 'duplicate project %s in %s' % | 389 | (project.name, self.manifestFile)) |
405 | (project.name, self.manifestFile)) | 390 | self._projects[project.name] = project |
406 | self._projects[project.name] = project | ||
407 | for subproject in project.subprojects: | ||
408 | recursively_add_projects(subproject) | ||
409 | recursively_add_projects(project) | ||
410 | if node.nodeName == 'repo-hooks': | 391 | if node.nodeName == 'repo-hooks': |
411 | # Get the name of the project and the (space-separated) list of enabled. | 392 | # Get the name of the project and the (space-separated) list of enabled. |
412 | repo_hooks_project = self._reqatt(node, 'in-project') | 393 | repo_hooks_project = self._reqatt(node, 'in-project') |
@@ -556,19 +537,11 @@ class XmlManifest(object): | |||
556 | 537 | ||
557 | return '\n'.join(cleanLines) | 538 | return '\n'.join(cleanLines) |
558 | 539 | ||
559 | def _JoinName(self, parent_name, name): | 540 | def _ParseProject(self, node): |
560 | return os.path.join(parent_name, name) | ||
561 | |||
562 | def _UnjoinName(self, parent_name, name): | ||
563 | return os.path.relpath(name, parent_name) | ||
564 | |||
565 | def _ParseProject(self, node, parent = None): | ||
566 | """ | 541 | """ |
567 | reads a <project> element from the manifest file | 542 | reads a <project> element from the manifest file |
568 | """ | 543 | """ |
569 | name = self._reqatt(node, 'name') | 544 | name = self._reqatt(node, 'name') |
570 | if parent: | ||
571 | name = self._JoinName(parent.name, name) | ||
572 | 545 | ||
573 | remote = self._get_remote(node) | 546 | remote = self._get_remote(node) |
574 | if remote is None: | 547 | if remote is None: |
@@ -613,66 +586,37 @@ class XmlManifest(object): | |||
613 | groups = node.getAttribute('groups') | 586 | groups = node.getAttribute('groups') |
614 | groups = [x for x in re.split('[,\s]+', groups) if x] | 587 | groups = [x for x in re.split('[,\s]+', groups) if x] |
615 | 588 | ||
616 | if parent is None: | 589 | default_groups = ['all', 'name:%s' % name, 'path:%s' % path] |
617 | relpath, worktree, gitdir = self.GetProjectPaths(name, path) | ||
618 | else: | ||
619 | relpath, worktree, gitdir = self.GetSubprojectPaths(parent, path) | ||
620 | |||
621 | default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath] | ||
622 | groups.extend(set(default_groups).difference(groups)) | 590 | groups.extend(set(default_groups).difference(groups)) |
623 | 591 | ||
592 | if self.IsMirror: | ||
593 | worktree = None | ||
594 | gitdir = os.path.join(self.topdir, '%s.git' % name) | ||
595 | else: | ||
596 | worktree = os.path.join(self.topdir, path).replace('\\', '/') | ||
597 | gitdir = os.path.join(self.repodir, 'projects/%s.git' % path) | ||
598 | |||
624 | project = Project(manifest = self, | 599 | project = Project(manifest = self, |
625 | name = name, | 600 | name = name, |
626 | remote = remote.ToRemoteSpec(name), | 601 | remote = remote.ToRemoteSpec(name), |
627 | gitdir = gitdir, | 602 | gitdir = gitdir, |
628 | worktree = worktree, | 603 | worktree = worktree, |
629 | relpath = relpath, | 604 | relpath = path, |
630 | revisionExpr = revisionExpr, | 605 | revisionExpr = revisionExpr, |
631 | revisionId = None, | 606 | revisionId = None, |
632 | rebase = rebase, | 607 | rebase = rebase, |
633 | groups = groups, | 608 | groups = groups, |
634 | sync_c = sync_c, | 609 | sync_c = sync_c, |
635 | upstream = upstream, | 610 | upstream = upstream) |
636 | parent = parent) | ||
637 | 611 | ||
638 | for n in node.childNodes: | 612 | for n in node.childNodes: |
639 | if n.nodeName == 'copyfile': | 613 | if n.nodeName == 'copyfile': |
640 | self._ParseCopyFile(project, n) | 614 | self._ParseCopyFile(project, n) |
641 | if n.nodeName == 'annotation': | 615 | if n.nodeName == 'annotation': |
642 | self._ParseAnnotation(project, n) | 616 | self._ParseAnnotation(project, n) |
643 | if n.nodeName == 'project': | ||
644 | project.subprojects.append(self._ParseProject(n, parent = project)) | ||
645 | 617 | ||
646 | return project | 618 | return project |
647 | 619 | ||
648 | def GetProjectPaths(self, name, path): | ||
649 | relpath = path | ||
650 | if self.IsMirror: | ||
651 | worktree = None | ||
652 | gitdir = os.path.join(self.topdir, '%s.git' % name) | ||
653 | else: | ||
654 | worktree = os.path.join(self.topdir, path).replace('\\', '/') | ||
655 | gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path) | ||
656 | return relpath, worktree, gitdir | ||
657 | |||
658 | def GetSubprojectName(self, parent, submodule_path): | ||
659 | return os.path.join(parent.name, submodule_path) | ||
660 | |||
661 | def _JoinRelpath(self, parent_relpath, relpath): | ||
662 | return os.path.join(parent_relpath, relpath) | ||
663 | |||
664 | def _UnjoinRelpath(self, parent_relpath, relpath): | ||
665 | return os.path.relpath(relpath, parent_relpath) | ||
666 | |||
667 | def GetSubprojectPaths(self, parent, path): | ||
668 | relpath = self._JoinRelpath(parent.relpath, path) | ||
669 | gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path) | ||
670 | if self.IsMirror: | ||
671 | worktree = None | ||
672 | else: | ||
673 | worktree = os.path.join(parent.worktree, path).replace('\\', '/') | ||
674 | return relpath, worktree, gitdir | ||
675 | |||
676 | def _ParseCopyFile(self, project, node): | 620 | def _ParseCopyFile(self, project, node): |
677 | src = self._reqatt(node, 'src') | 621 | src = self._reqatt(node, 'src') |
678 | dest = self._reqatt(node, 'dest') | 622 | dest = self._reqatt(node, 'dest') |