diff options
Diffstat (limited to 'command.py')
| -rw-r--r-- | command.py | 33 |
1 files changed, 24 insertions, 9 deletions
| @@ -17,6 +17,8 @@ import os | |||
| 17 | import optparse | 17 | import optparse |
| 18 | import sys | 18 | import sys |
| 19 | 19 | ||
| 20 | import manifest_loader | ||
| 21 | |||
| 20 | from error import NoSuchProjectError | 22 | from error import NoSuchProjectError |
| 21 | 23 | ||
| 22 | class Command(object): | 24 | class Command(object): |
| @@ -24,7 +26,6 @@ class Command(object): | |||
| 24 | """ | 26 | """ |
| 25 | 27 | ||
| 26 | common = False | 28 | common = False |
| 27 | manifest = None | ||
| 28 | _optparse = None | 29 | _optparse = None |
| 29 | 30 | ||
| 30 | def WantPager(self, opt): | 31 | def WantPager(self, opt): |
| @@ -57,10 +58,25 @@ class Command(object): | |||
| 57 | """ | 58 | """ |
| 58 | raise NotImplementedError | 59 | raise NotImplementedError |
| 59 | 60 | ||
| 61 | @property | ||
| 62 | def manifest(self): | ||
| 63 | return self.GetManifest() | ||
| 64 | |||
| 65 | def GetManifest(self, reparse=False, type=None): | ||
| 66 | return manifest_loader.GetManifest(self.repodir, | ||
| 67 | reparse=reparse, | ||
| 68 | type=type) | ||
| 69 | |||
| 60 | def GetProjects(self, args, missing_ok=False): | 70 | def GetProjects(self, args, missing_ok=False): |
| 61 | """A list of projects that match the arguments. | 71 | """A list of projects that match the arguments. |
| 62 | """ | 72 | """ |
| 63 | all = self.manifest.projects | 73 | all = self.manifest.projects |
| 74 | |||
| 75 | mp = self.manifest.manifestProject | ||
| 76 | if mp.relpath == '.': | ||
| 77 | all = dict(all) | ||
| 78 | all[mp.name] = mp | ||
| 79 | |||
| 64 | result = [] | 80 | result = [] |
| 65 | 81 | ||
| 66 | if not args: | 82 | if not args: |
| @@ -74,27 +90,26 @@ class Command(object): | |||
| 74 | project = all.get(arg) | 90 | project = all.get(arg) |
| 75 | 91 | ||
| 76 | if not project: | 92 | if not project: |
| 77 | path = os.path.abspath(arg) | 93 | path = os.path.abspath(arg).replace('\\', '/') |
| 78 | 94 | ||
| 79 | if not by_path: | 95 | if not by_path: |
| 80 | by_path = dict() | 96 | by_path = dict() |
| 81 | for p in all.values(): | 97 | for p in all.values(): |
| 82 | by_path[p.worktree] = p | 98 | by_path[p.worktree] = p |
| 83 | 99 | ||
| 84 | if os.path.exists(path): | 100 | try: |
| 101 | project = by_path[path] | ||
| 102 | except KeyError: | ||
| 103 | oldpath = None | ||
| 85 | while path \ | 104 | while path \ |
| 86 | and path != '/' \ | 105 | and path != oldpath \ |
| 87 | and path != self.manifest.topdir: | 106 | and path != self.manifest.topdir: |
| 88 | try: | 107 | try: |
| 89 | project = by_path[path] | 108 | project = by_path[path] |
| 90 | break | 109 | break |
| 91 | except KeyError: | 110 | except KeyError: |
| 111 | oldpath = path | ||
| 92 | path = os.path.dirname(path) | 112 | path = os.path.dirname(path) |
| 93 | else: | ||
| 94 | try: | ||
| 95 | project = by_path[path] | ||
| 96 | except KeyError: | ||
| 97 | pass | ||
| 98 | 113 | ||
| 99 | if not project: | 114 | if not project: |
| 100 | raise NoSuchProjectError(arg) | 115 | raise NoSuchProjectError(arg) |
