summaryrefslogtreecommitdiffstats
path: root/subcmds/diff.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/diff.py')
-rw-r--r--subcmds/diff.py85
1 files changed, 47 insertions, 38 deletions
diff --git a/subcmds/diff.py b/subcmds/diff.py
index a606ee9a..5c627c0c 100644
--- a/subcmds/diff.py
+++ b/subcmds/diff.py
@@ -19,54 +19,63 @@ from command import DEFAULT_LOCAL_JOBS, PagedCommand
19 19
20 20
21class Diff(PagedCommand): 21class Diff(PagedCommand):
22 COMMON = True 22 COMMON = True
23 helpSummary = "Show changes between commit and working tree" 23 helpSummary = "Show changes between commit and working tree"
24 helpUsage = """ 24 helpUsage = """
25%prog [<project>...] 25%prog [<project>...]
26 26
27The -u option causes '%prog' to generate diff output with file paths 27The -u option causes '%prog' to generate diff output with file paths
28relative to the repository root, so the output can be applied 28relative to the repository root, so the output can be applied
29to the Unix 'patch' command. 29to the Unix 'patch' command.
30""" 30"""
31 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS 31 PARALLEL_JOBS = DEFAULT_LOCAL_JOBS
32 32
33 def _Options(self, p): 33 def _Options(self, p):
34 p.add_option('-u', '--absolute', 34 p.add_option(
35 dest='absolute', action='store_true', 35 "-u",
36 help='paths are relative to the repository root') 36 "--absolute",
37 dest="absolute",
38 action="store_true",
39 help="paths are relative to the repository root",
40 )
37 41
38 def _ExecuteOne(self, absolute, local, project): 42 def _ExecuteOne(self, absolute, local, project):
39 """Obtains the diff for a specific project. 43 """Obtains the diff for a specific project.
40 44
41 Args: 45 Args:
42 absolute: Paths are relative to the root. 46 absolute: Paths are relative to the root.
43 local: a boolean, if True, the path is relative to the local 47 local: a boolean, if True, the path is relative to the local
44 (sub)manifest. If false, the path is relative to the 48 (sub)manifest. If false, the path is relative to the outermost
45 outermost manifest. 49 manifest.
46 project: Project to get status of. 50 project: Project to get status of.
47 51
48 Returns: 52 Returns:
49 The status of the project. 53 The status of the project.
50 """ 54 """
51 buf = io.StringIO() 55 buf = io.StringIO()
52 ret = project.PrintWorkTreeDiff(absolute, output_redir=buf, local=local) 56 ret = project.PrintWorkTreeDiff(absolute, output_redir=buf, local=local)
53 return (ret, buf.getvalue()) 57 return (ret, buf.getvalue())
54 58
55 def Execute(self, opt, args): 59 def Execute(self, opt, args):
56 all_projects = self.GetProjects(args, all_manifests=not opt.this_manifest_only) 60 all_projects = self.GetProjects(
61 args, all_manifests=not opt.this_manifest_only
62 )
57 63
58 def _ProcessResults(_pool, _output, results): 64 def _ProcessResults(_pool, _output, results):
59 ret = 0 65 ret = 0
60 for (state, output) in results: 66 for state, output in results:
61 if output: 67 if output:
62 print(output, end='') 68 print(output, end="")
63 if not state: 69 if not state:
64 ret = 1 70 ret = 1
65 return ret 71 return ret
66 72
67 return self.ExecuteInParallel( 73 return self.ExecuteInParallel(
68 opt.jobs, 74 opt.jobs,
69 functools.partial(self._ExecuteOne, opt.absolute, opt.this_manifest_only), 75 functools.partial(
70 all_projects, 76 self._ExecuteOne, opt.absolute, opt.this_manifest_only
71 callback=_ProcessResults, 77 ),
72 ordered=True) 78 all_projects,
79 callback=_ProcessResults,
80 ordered=True,
81 )