diff options
Diffstat (limited to 'subcmds/diff.py')
-rw-r--r-- | subcmds/diff.py | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/subcmds/diff.py b/subcmds/diff.py index cdc262e6..4966bb1a 100644 --- a/subcmds/diff.py +++ b/subcmds/diff.py | |||
@@ -14,9 +14,8 @@ | |||
14 | 14 | ||
15 | import functools | 15 | import functools |
16 | import io | 16 | import io |
17 | import multiprocessing | ||
18 | 17 | ||
19 | from command import DEFAULT_LOCAL_JOBS, PagedCommand, WORKER_BATCH_SIZE | 18 | from command import DEFAULT_LOCAL_JOBS, PagedCommand |
20 | 19 | ||
21 | 20 | ||
22 | class Diff(PagedCommand): | 21 | class Diff(PagedCommand): |
@@ -36,7 +35,7 @@ to the Unix 'patch' command. | |||
36 | dest='absolute', action='store_true', | 35 | dest='absolute', action='store_true', |
37 | help='Paths are relative to the repository root') | 36 | help='Paths are relative to the repository root') |
38 | 37 | ||
39 | def _DiffHelper(self, absolute, project): | 38 | def _ExecuteOne(self, absolute, project): |
40 | """Obtains the diff for a specific project. | 39 | """Obtains the diff for a specific project. |
41 | 40 | ||
42 | Args: | 41 | Args: |
@@ -51,22 +50,20 @@ to the Unix 'patch' command. | |||
51 | return (ret, buf.getvalue()) | 50 | return (ret, buf.getvalue()) |
52 | 51 | ||
53 | def Execute(self, opt, args): | 52 | def Execute(self, opt, args): |
54 | ret = 0 | ||
55 | all_projects = self.GetProjects(args) | 53 | all_projects = self.GetProjects(args) |
56 | 54 | ||
57 | # NB: Multiprocessing is heavy, so don't spin it up for one job. | 55 | def _ProcessResults(_pool, _output, results): |
58 | if len(all_projects) == 1 or opt.jobs == 1: | 56 | ret = 0 |
59 | for project in all_projects: | 57 | for (state, output) in results: |
60 | if not project.PrintWorkTreeDiff(opt.absolute): | 58 | if output: |
59 | print(output, end='') | ||
60 | if not state: | ||
61 | ret = 1 | 61 | ret = 1 |
62 | else: | 62 | return ret |
63 | with multiprocessing.Pool(opt.jobs) as pool: | ||
64 | states = pool.imap(functools.partial(self._DiffHelper, opt.absolute), | ||
65 | all_projects, WORKER_BATCH_SIZE) | ||
66 | for (state, output) in states: | ||
67 | if output: | ||
68 | print(output, end='') | ||
69 | if not state: | ||
70 | ret = 1 | ||
71 | 63 | ||
72 | return ret | 64 | return self.ExecuteInParallel( |
65 | opt.jobs, | ||
66 | functools.partial(self._ExecuteOne, opt.absolute), | ||
67 | all_projects, | ||
68 | callback=_ProcessResults, | ||
69 | ordered=True) | ||