summaryrefslogtreecommitdiffstats
path: root/subcmds/grep.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/grep.py')
-rw-r--r--subcmds/grep.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/subcmds/grep.py b/subcmds/grep.py
index 9a4a8a36..6cb1445a 100644
--- a/subcmds/grep.py
+++ b/subcmds/grep.py
@@ -13,11 +13,10 @@
13# limitations under the License. 13# limitations under the License.
14 14
15import functools 15import functools
16import multiprocessing
17import sys 16import sys
18 17
19from color import Coloring 18from color import Coloring
20from command import DEFAULT_LOCAL_JOBS, PagedCommand, WORKER_BATCH_SIZE 19from command import DEFAULT_LOCAL_JOBS, PagedCommand
21from error import GitError 20from error import GitError
22from git_command import GitCommand 21from git_command import GitCommand
23 22
@@ -173,7 +172,7 @@ contain a line that matches both expressions:
173 return (project, p.Wait(), p.stdout, p.stderr) 172 return (project, p.Wait(), p.stdout, p.stderr)
174 173
175 @staticmethod 174 @staticmethod
176 def _ProcessResults(out, full_name, have_rev, results): 175 def _ProcessResults(full_name, have_rev, _pool, out, results):
177 git_failed = False 176 git_failed = False
178 bad_rev = False 177 bad_rev = False
179 have_match = False 178 have_match = False
@@ -256,18 +255,13 @@ contain a line that matches both expressions:
256 cmd_argv.extend(opt.revision) 255 cmd_argv.extend(opt.revision)
257 cmd_argv.append('--') 256 cmd_argv.append('--')
258 257
259 process_results = functools.partial( 258 git_failed, bad_rev, have_match = self.ExecuteInParallel(
260 self._ProcessResults, out, full_name, have_rev) 259 opt.jobs,
261 # NB: Multiprocessing is heavy, so don't spin it up for one job. 260 functools.partial(self._ExecuteOne, cmd_argv),
262 if len(projects) == 1 or opt.jobs == 1: 261 projects,
263 git_failed, bad_rev, have_match = process_results( 262 callback=functools.partial(self._ProcessResults, full_name, have_rev),
264 self._ExecuteOne(cmd_argv, x) for x in projects) 263 output=out,
265 else: 264 ordered=True)
266 with multiprocessing.Pool(opt.jobs) as pool:
267 results = pool.imap(
268 functools.partial(self._ExecuteOne, cmd_argv), projects,
269 chunksize=WORKER_BATCH_SIZE)
270 git_failed, bad_rev, have_match = process_results(results)
271 265
272 if git_failed: 266 if git_failed:
273 sys.exit(1) 267 sys.exit(1)