diff options
Diffstat (limited to 'subcmds/diff.py')
-rw-r--r-- | subcmds/diff.py | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/subcmds/diff.py b/subcmds/diff.py index fa41e70e..00a7ec29 100644 --- a/subcmds/diff.py +++ b/subcmds/diff.py | |||
@@ -1,5 +1,3 @@ | |||
1 | # -*- coding:utf-8 -*- | ||
2 | # | ||
3 | # Copyright (C) 2008 The Android Open Source Project | 1 | # Copyright (C) 2008 The Android Open Source Project |
4 | # | 2 | # |
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -14,10 +12,14 @@ | |||
14 | # See the License for the specific language governing permissions and | 12 | # See the License for the specific language governing permissions and |
15 | # limitations under the License. | 13 | # limitations under the License. |
16 | 14 | ||
17 | from command import PagedCommand | 15 | import functools |
16 | import io | ||
17 | |||
18 | from command import DEFAULT_LOCAL_JOBS, PagedCommand | ||
19 | |||
18 | 20 | ||
19 | class Diff(PagedCommand): | 21 | class Diff(PagedCommand): |
20 | common = True | 22 | COMMON = True |
21 | helpSummary = "Show changes between commit and working tree" | 23 | helpSummary = "Show changes between commit and working tree" |
22 | helpUsage = """ | 24 | helpUsage = """ |
23 | %prog [<project>...] | 25 | %prog [<project>...] |
@@ -26,19 +28,42 @@ The -u option causes '%prog' to generate diff output with file paths | |||
26 | relative to the repository root, so the output can be applied | 28 | relative to the repository root, so the output can be applied |
27 | to the Unix 'patch' command. | 29 | to the Unix 'patch' command. |
28 | """ | 30 | """ |
31 | PARALLEL_JOBS = DEFAULT_LOCAL_JOBS | ||
29 | 32 | ||
30 | def _Options(self, p): | 33 | def _Options(self, p): |
31 | def cmd(option, opt_str, value, parser): | ||
32 | setattr(parser.values, option.dest, list(parser.rargs)) | ||
33 | while parser.rargs: | ||
34 | del parser.rargs[0] | ||
35 | p.add_option('-u', '--absolute', | 34 | p.add_option('-u', '--absolute', |
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') |
37 | |||
38 | def _ExecuteOne(self, absolute, project): | ||
39 | """Obtains the diff for a specific project. | ||
40 | |||
41 | Args: | ||
42 | absolute: Paths are relative to the root. | ||
43 | project: Project to get status of. | ||
44 | |||
45 | Returns: | ||
46 | The status of the project. | ||
47 | """ | ||
48 | buf = io.StringIO() | ||
49 | ret = project.PrintWorkTreeDiff(absolute, output_redir=buf) | ||
50 | return (ret, buf.getvalue()) | ||
38 | 51 | ||
39 | def Execute(self, opt, args): | 52 | def Execute(self, opt, args): |
40 | ret = 0 | 53 | all_projects = self.GetProjects(args) |
41 | for project in self.GetProjects(args): | 54 | |
42 | if not project.PrintWorkTreeDiff(opt.absolute): | 55 | def _ProcessResults(_pool, _output, results): |
43 | ret = 1 | 56 | ret = 0 |
44 | return ret | 57 | for (state, output) in results: |
58 | if output: | ||
59 | print(output, end='') | ||
60 | if not state: | ||
61 | ret = 1 | ||
62 | return ret | ||
63 | |||
64 | return self.ExecuteInParallel( | ||
65 | opt.jobs, | ||
66 | functools.partial(self._ExecuteOne, opt.absolute), | ||
67 | all_projects, | ||
68 | callback=_ProcessResults, | ||
69 | ordered=True) | ||