diff options
author | Takeshi Kanemoto <takeshi.kanemoto@sonymobile.com> | 2016-01-26 14:11:35 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2016-04-05 07:28:27 +0000 |
commit | 1f0564406ba5aab11b21a83d193485ee6597f213 (patch) | |
tree | 533f5c7a21032a634161c365f781efe8b340ecfc | |
parent | 936d6185eb9bb802a3b25982bc71c6bc58633f43 (diff) | |
download | git-repo-1f0564406ba5aab11b21a83d193485ee6597f213.tar.gz |
Add --inverse-regex option to forall subcommand
Make it possible to exclude projects using regex/wildcard.
The syntax is similar to that of the -r option, e.g.:
repo forall -i ^platform/ ^device/ -c 'echo $REPO_PROJECT'
Change-Id: Id250de5665152228c044c79337d3ac15b5696484
-rw-r--r-- | command.py | 10 | ||||
-rw-r--r-- | subcmds/forall.py | 11 |
2 files changed, 16 insertions, 5 deletions
@@ -193,14 +193,20 @@ class Command(object): | |||
193 | result.sort(key=_getpath) | 193 | result.sort(key=_getpath) |
194 | return result | 194 | return result |
195 | 195 | ||
196 | def FindProjects(self, args): | 196 | def FindProjects(self, args, inverse=False): |
197 | result = [] | 197 | result = [] |
198 | patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args] | 198 | patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args] |
199 | for project in self.GetProjects(''): | 199 | for project in self.GetProjects(''): |
200 | for pattern in patterns: | 200 | for pattern in patterns: |
201 | if pattern.search(project.name) or pattern.search(project.relpath): | 201 | match = pattern.search(project.name) or pattern.search(project.relpath) |
202 | if not inverse and match: | ||
202 | result.append(project) | 203 | result.append(project) |
203 | break | 204 | break |
205 | if inverse and match: | ||
206 | break | ||
207 | else: | ||
208 | if inverse: | ||
209 | result.append(project) | ||
204 | result.sort(key=lambda project: project.relpath) | 210 | result.sort(key=lambda project: project.relpath) |
205 | return result | 211 | return result |
206 | 212 | ||
diff --git a/subcmds/forall.py b/subcmds/forall.py index b10f34b3..07ee8d58 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -120,6 +120,9 @@ without iterating through the remaining projects. | |||
120 | p.add_option('-r', '--regex', | 120 | p.add_option('-r', '--regex', |
121 | dest='regex', action='store_true', | 121 | dest='regex', action='store_true', |
122 | help="Execute the command only on projects matching regex or wildcard expression") | 122 | help="Execute the command only on projects matching regex or wildcard expression") |
123 | p.add_option('-i', '--inverse-regex', | ||
124 | dest='inverse_regex', action='store_true', | ||
125 | help="Execute the command only on projects not matching regex or wildcard expression") | ||
123 | p.add_option('-g', '--groups', | 126 | p.add_option('-g', '--groups', |
124 | dest='groups', | 127 | dest='groups', |
125 | help="Execute the command only on projects matching the specified groups") | 128 | help="Execute the command only on projects matching the specified groups") |
@@ -215,10 +218,12 @@ without iterating through the remaining projects. | |||
215 | if os.path.isfile(smart_sync_manifest_path): | 218 | if os.path.isfile(smart_sync_manifest_path): |
216 | self.manifest.Override(smart_sync_manifest_path) | 219 | self.manifest.Override(smart_sync_manifest_path) |
217 | 220 | ||
218 | if not opt.regex: | 221 | if opt.regex: |
219 | projects = self.GetProjects(args, groups=opt.groups) | ||
220 | else: | ||
221 | projects = self.FindProjects(args) | 222 | projects = self.FindProjects(args) |
223 | elif opt.inverse_regex: | ||
224 | projects = self.FindProjects(args, inverse=True) | ||
225 | else: | ||
226 | projects = self.GetProjects(args, groups=opt.groups) | ||
222 | 227 | ||
223 | os.environ['REPO_COUNT'] = str(len(projects)) | 228 | os.environ['REPO_COUNT'] = str(len(projects)) |
224 | 229 | ||