diff options
author | Gavin Mak <gavinmak@google.com> | 2023-03-11 06:46:20 +0000 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-22 17:46:28 +0000 |
commit | ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 (patch) | |
tree | dc33ba0e56825b3e007d0589891756724725a465 /subcmds/diff.py | |
parent | 1604cf255f8c1786a23388db6d5277ac7949a24a (diff) | |
download | git-repo-ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1.tar.gz |
Format codebase with black and check formatting in CQ
Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught
by flake8. Also check black formatting in run_tests (and CQ).
Bug: b/267675342
Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'subcmds/diff.py')
-rw-r--r-- | subcmds/diff.py | 85 |
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 | ||
21 | class Diff(PagedCommand): | 21 | class 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 | ||
27 | The -u option causes '%prog' to generate diff output with file paths | 27 | The -u option causes '%prog' to generate diff output with file paths |
28 | relative to the repository root, so the output can be applied | 28 | relative to the repository root, so the output can be applied |
29 | to the Unix 'patch' command. | 29 | to 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 | ) | ||