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/info.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/info.py')
-rw-r--r-- | subcmds/info.py | 413 |
1 files changed, 222 insertions, 191 deletions
diff --git a/subcmds/info.py b/subcmds/info.py index baa4c5b1..6e7f3ed2 100644 --- a/subcmds/info.py +++ b/subcmds/info.py | |||
@@ -20,203 +20,234 @@ from git_refs import R_M, R_HEADS | |||
20 | 20 | ||
21 | 21 | ||
22 | class _Coloring(Coloring): | 22 | class _Coloring(Coloring): |
23 | def __init__(self, config): | 23 | def __init__(self, config): |
24 | Coloring.__init__(self, config, "status") | 24 | Coloring.__init__(self, config, "status") |
25 | 25 | ||
26 | 26 | ||
27 | class Info(PagedCommand): | 27 | class Info(PagedCommand): |
28 | COMMON = True | 28 | COMMON = True |
29 | helpSummary = "Get info on the manifest branch, current branch or unmerged branches" | 29 | helpSummary = ( |
30 | helpUsage = "%prog [-dl] [-o [-c]] [<project>...]" | 30 | "Get info on the manifest branch, current branch or unmerged branches" |
31 | 31 | ) | |
32 | def _Options(self, p): | 32 | helpUsage = "%prog [-dl] [-o [-c]] [<project>...]" |
33 | p.add_option('-d', '--diff', | 33 | |
34 | dest='all', action='store_true', | 34 | def _Options(self, p): |
35 | help="show full info and commit diff including remote branches") | 35 | p.add_option( |
36 | p.add_option('-o', '--overview', | 36 | "-d", |
37 | dest='overview', action='store_true', | 37 | "--diff", |
38 | help='show overview of all local commits') | 38 | dest="all", |
39 | p.add_option('-c', '--current-branch', | 39 | action="store_true", |
40 | dest="current_branch", action="store_true", | 40 | help="show full info and commit diff including remote branches", |
41 | help="consider only checked out branches") | 41 | ) |
42 | p.add_option('--no-current-branch', | 42 | p.add_option( |
43 | dest='current_branch', action='store_false', | 43 | "-o", |
44 | help='consider all local branches') | 44 | "--overview", |
45 | # Turn this into a warning & remove this someday. | 45 | dest="overview", |
46 | p.add_option('-b', | 46 | action="store_true", |
47 | dest='current_branch', action='store_true', | 47 | help="show overview of all local commits", |
48 | help=optparse.SUPPRESS_HELP) | 48 | ) |
49 | p.add_option('-l', '--local-only', | 49 | p.add_option( |
50 | dest="local", action="store_true", | 50 | "-c", |
51 | help="disable all remote operations") | 51 | "--current-branch", |
52 | 52 | dest="current_branch", | |
53 | def Execute(self, opt, args): | 53 | action="store_true", |
54 | self.out = _Coloring(self.client.globalConfig) | 54 | help="consider only checked out branches", |
55 | self.heading = self.out.printer('heading', attr='bold') | 55 | ) |
56 | self.headtext = self.out.nofmt_printer('headtext', fg='yellow') | 56 | p.add_option( |
57 | self.redtext = self.out.printer('redtext', fg='red') | 57 | "--no-current-branch", |
58 | self.sha = self.out.printer("sha", fg='yellow') | 58 | dest="current_branch", |
59 | self.text = self.out.nofmt_printer('text') | 59 | action="store_false", |
60 | self.dimtext = self.out.printer('dimtext', attr='dim') | 60 | help="consider all local branches", |
61 | 61 | ) | |
62 | self.opt = opt | 62 | # Turn this into a warning & remove this someday. |
63 | 63 | p.add_option( | |
64 | if not opt.this_manifest_only: | 64 | "-b", |
65 | self.manifest = self.manifest.outer_client | 65 | dest="current_branch", |
66 | manifestConfig = self.manifest.manifestProject.config | 66 | action="store_true", |
67 | mergeBranch = manifestConfig.GetBranch("default").merge | 67 | help=optparse.SUPPRESS_HELP, |
68 | manifestGroups = self.manifest.GetGroupsStr() | 68 | ) |
69 | 69 | p.add_option( | |
70 | self.heading("Manifest branch: ") | 70 | "-l", |
71 | if self.manifest.default.revisionExpr: | 71 | "--local-only", |
72 | self.headtext(self.manifest.default.revisionExpr) | 72 | dest="local", |
73 | self.out.nl() | 73 | action="store_true", |
74 | self.heading("Manifest merge branch: ") | 74 | help="disable all remote operations", |
75 | self.headtext(mergeBranch) | 75 | ) |
76 | self.out.nl() | 76 | |
77 | self.heading("Manifest groups: ") | 77 | def Execute(self, opt, args): |
78 | self.headtext(manifestGroups) | 78 | self.out = _Coloring(self.client.globalConfig) |
79 | self.out.nl() | 79 | self.heading = self.out.printer("heading", attr="bold") |
80 | 80 | self.headtext = self.out.nofmt_printer("headtext", fg="yellow") | |
81 | self.printSeparator() | 81 | self.redtext = self.out.printer("redtext", fg="red") |
82 | 82 | self.sha = self.out.printer("sha", fg="yellow") | |
83 | if not opt.overview: | 83 | self.text = self.out.nofmt_printer("text") |
84 | self._printDiffInfo(opt, args) | 84 | self.dimtext = self.out.printer("dimtext", attr="dim") |
85 | else: | 85 | |
86 | self._printCommitOverview(opt, args) | 86 | self.opt = opt |
87 | 87 | ||
88 | def printSeparator(self): | 88 | if not opt.this_manifest_only: |
89 | self.text("----------------------------") | 89 | self.manifest = self.manifest.outer_client |
90 | self.out.nl() | 90 | manifestConfig = self.manifest.manifestProject.config |
91 | 91 | mergeBranch = manifestConfig.GetBranch("default").merge | |
92 | def _printDiffInfo(self, opt, args): | 92 | manifestGroups = self.manifest.GetGroupsStr() |
93 | # We let exceptions bubble up to main as they'll be well structured. | 93 | |
94 | projs = self.GetProjects(args, all_manifests=not opt.this_manifest_only) | 94 | self.heading("Manifest branch: ") |
95 | 95 | if self.manifest.default.revisionExpr: | |
96 | for p in projs: | 96 | self.headtext(self.manifest.default.revisionExpr) |
97 | self.heading("Project: ") | 97 | self.out.nl() |
98 | self.headtext(p.name) | 98 | self.heading("Manifest merge branch: ") |
99 | self.out.nl() | 99 | self.headtext(mergeBranch) |
100 | 100 | self.out.nl() | |
101 | self.heading("Mount path: ") | 101 | self.heading("Manifest groups: ") |
102 | self.headtext(p.worktree) | 102 | self.headtext(manifestGroups) |
103 | self.out.nl() | 103 | self.out.nl() |
104 | 104 | ||
105 | self.heading("Current revision: ") | 105 | self.printSeparator() |
106 | self.headtext(p.GetRevisionId()) | 106 | |
107 | self.out.nl() | 107 | if not opt.overview: |
108 | 108 | self._printDiffInfo(opt, args) | |
109 | currentBranch = p.CurrentBranch | 109 | else: |
110 | if currentBranch: | 110 | self._printCommitOverview(opt, args) |
111 | self.heading('Current branch: ') | 111 | |
112 | self.headtext(currentBranch) | 112 | def printSeparator(self): |
113 | self.text("----------------------------") | ||
113 | self.out.nl() | 114 | self.out.nl() |
114 | 115 | ||
115 | self.heading("Manifest revision: ") | 116 | def _printDiffInfo(self, opt, args): |
116 | self.headtext(p.revisionExpr) | 117 | # We let exceptions bubble up to main as they'll be well structured. |
117 | self.out.nl() | 118 | projs = self.GetProjects(args, all_manifests=not opt.this_manifest_only) |
118 | 119 | ||
119 | localBranches = list(p.GetBranches().keys()) | 120 | for p in projs: |
120 | self.heading("Local Branches: ") | 121 | self.heading("Project: ") |
121 | self.redtext(str(len(localBranches))) | 122 | self.headtext(p.name) |
122 | if localBranches: | 123 | self.out.nl() |
123 | self.text(" [") | 124 | |
124 | self.text(", ".join(localBranches)) | 125 | self.heading("Mount path: ") |
125 | self.text("]") | 126 | self.headtext(p.worktree) |
126 | self.out.nl() | 127 | self.out.nl() |
127 | 128 | ||
128 | if self.opt.all: | 129 | self.heading("Current revision: ") |
129 | self.findRemoteLocalDiff(p) | 130 | self.headtext(p.GetRevisionId()) |
130 | 131 | self.out.nl() | |
131 | self.printSeparator() | 132 | |
132 | 133 | currentBranch = p.CurrentBranch | |
133 | def findRemoteLocalDiff(self, project): | 134 | if currentBranch: |
134 | # Fetch all the latest commits. | 135 | self.heading("Current branch: ") |
135 | if not self.opt.local: | 136 | self.headtext(currentBranch) |
136 | project.Sync_NetworkHalf(quiet=True, current_branch_only=True) | 137 | self.out.nl() |
137 | 138 | ||
138 | branch = self.manifest.manifestProject.config.GetBranch('default').merge | 139 | self.heading("Manifest revision: ") |
139 | if branch.startswith(R_HEADS): | 140 | self.headtext(p.revisionExpr) |
140 | branch = branch[len(R_HEADS):] | 141 | self.out.nl() |
141 | logTarget = R_M + branch | 142 | |
142 | 143 | localBranches = list(p.GetBranches().keys()) | |
143 | bareTmp = project.bare_git._bare | 144 | self.heading("Local Branches: ") |
144 | project.bare_git._bare = False | 145 | self.redtext(str(len(localBranches))) |
145 | localCommits = project.bare_git.rev_list( | 146 | if localBranches: |
146 | '--abbrev=8', | 147 | self.text(" [") |
147 | '--abbrev-commit', | 148 | self.text(", ".join(localBranches)) |
148 | '--pretty=oneline', | 149 | self.text("]") |
149 | logTarget + "..", | 150 | self.out.nl() |
150 | '--') | 151 | |
151 | 152 | if self.opt.all: | |
152 | originCommits = project.bare_git.rev_list( | 153 | self.findRemoteLocalDiff(p) |
153 | '--abbrev=8', | 154 | |
154 | '--abbrev-commit', | 155 | self.printSeparator() |
155 | '--pretty=oneline', | 156 | |
156 | ".." + logTarget, | 157 | def findRemoteLocalDiff(self, project): |
157 | '--') | 158 | # Fetch all the latest commits. |
158 | project.bare_git._bare = bareTmp | 159 | if not self.opt.local: |
159 | 160 | project.Sync_NetworkHalf(quiet=True, current_branch_only=True) | |
160 | self.heading("Local Commits: ") | 161 | |
161 | self.redtext(str(len(localCommits))) | 162 | branch = self.manifest.manifestProject.config.GetBranch("default").merge |
162 | self.dimtext(" (on current branch)") | 163 | if branch.startswith(R_HEADS): |
163 | self.out.nl() | 164 | branch = branch[len(R_HEADS) :] |
164 | 165 | logTarget = R_M + branch | |
165 | for c in localCommits: | 166 | |
166 | split = c.split() | 167 | bareTmp = project.bare_git._bare |
167 | self.sha(split[0] + " ") | 168 | project.bare_git._bare = False |
168 | self.text(" ".join(split[1:])) | 169 | localCommits = project.bare_git.rev_list( |
169 | self.out.nl() | 170 | "--abbrev=8", |
170 | 171 | "--abbrev-commit", | |
171 | self.printSeparator() | 172 | "--pretty=oneline", |
172 | 173 | logTarget + "..", | |
173 | self.heading("Remote Commits: ") | 174 | "--", |
174 | self.redtext(str(len(originCommits))) | 175 | ) |
175 | self.out.nl() | 176 | |
176 | 177 | originCommits = project.bare_git.rev_list( | |
177 | for c in originCommits: | 178 | "--abbrev=8", |
178 | split = c.split() | 179 | "--abbrev-commit", |
179 | self.sha(split[0] + " ") | 180 | "--pretty=oneline", |
180 | self.text(" ".join(split[1:])) | 181 | ".." + logTarget, |
181 | self.out.nl() | 182 | "--", |
182 | 183 | ) | |
183 | def _printCommitOverview(self, opt, args): | 184 | project.bare_git._bare = bareTmp |
184 | all_branches = [] | 185 | |
185 | for project in self.GetProjects(args, all_manifests=not opt.this_manifest_only): | 186 | self.heading("Local Commits: ") |
186 | br = [project.GetUploadableBranch(x) | 187 | self.redtext(str(len(localCommits))) |
187 | for x in project.GetBranches()] | 188 | self.dimtext(" (on current branch)") |
188 | br = [x for x in br if x] | ||
189 | if self.opt.current_branch: | ||
190 | br = [x for x in br if x.name == project.CurrentBranch] | ||
191 | all_branches.extend(br) | ||
192 | |||
193 | if not all_branches: | ||
194 | return | ||
195 | |||
196 | self.out.nl() | ||
197 | self.heading('Projects Overview') | ||
198 | project = None | ||
199 | |||
200 | for branch in all_branches: | ||
201 | if project != branch.project: | ||
202 | project = branch.project | ||
203 | self.out.nl() | 189 | self.out.nl() |
204 | self.headtext(project.RelPath(local=opt.this_manifest_only)) | 190 | |
191 | for c in localCommits: | ||
192 | split = c.split() | ||
193 | self.sha(split[0] + " ") | ||
194 | self.text(" ".join(split[1:])) | ||
195 | self.out.nl() | ||
196 | |||
197 | self.printSeparator() | ||
198 | |||
199 | self.heading("Remote Commits: ") | ||
200 | self.redtext(str(len(originCommits))) | ||
205 | self.out.nl() | 201 | self.out.nl() |
206 | 202 | ||
207 | commits = branch.commits | 203 | for c in originCommits: |
208 | date = branch.date | 204 | split = c.split() |
209 | self.text('%s %-33s (%2d commit%s, %s)' % ( | 205 | self.sha(split[0] + " ") |
210 | branch.name == project.CurrentBranch and '*' or ' ', | 206 | self.text(" ".join(split[1:])) |
211 | branch.name, | 207 | self.out.nl() |
212 | len(commits), | 208 | |
213 | len(commits) != 1 and 's' or '', | 209 | def _printCommitOverview(self, opt, args): |
214 | date)) | 210 | all_branches = [] |
215 | self.out.nl() | 211 | for project in self.GetProjects( |
216 | 212 | args, all_manifests=not opt.this_manifest_only | |
217 | for commit in commits: | 213 | ): |
218 | split = commit.split() | 214 | br = [project.GetUploadableBranch(x) for x in project.GetBranches()] |
219 | self.text('{0:38}{1} '.format('', '-')) | 215 | br = [x for x in br if x] |
220 | self.sha(split[0] + " ") | 216 | if self.opt.current_branch: |
221 | self.text(" ".join(split[1:])) | 217 | br = [x for x in br if x.name == project.CurrentBranch] |
218 | all_branches.extend(br) | ||
219 | |||
220 | if not all_branches: | ||
221 | return | ||
222 | |||
222 | self.out.nl() | 223 | self.out.nl() |
224 | self.heading("Projects Overview") | ||
225 | project = None | ||
226 | |||
227 | for branch in all_branches: | ||
228 | if project != branch.project: | ||
229 | project = branch.project | ||
230 | self.out.nl() | ||
231 | self.headtext(project.RelPath(local=opt.this_manifest_only)) | ||
232 | self.out.nl() | ||
233 | |||
234 | commits = branch.commits | ||
235 | date = branch.date | ||
236 | self.text( | ||
237 | "%s %-33s (%2d commit%s, %s)" | ||
238 | % ( | ||
239 | branch.name == project.CurrentBranch and "*" or " ", | ||
240 | branch.name, | ||
241 | len(commits), | ||
242 | len(commits) != 1 and "s" or "", | ||
243 | date, | ||
244 | ) | ||
245 | ) | ||
246 | self.out.nl() | ||
247 | |||
248 | for commit in commits: | ||
249 | split = commit.split() | ||
250 | self.text("{0:38}{1} ".format("", "-")) | ||
251 | self.sha(split[0] + " ") | ||
252 | self.text(" ".join(split[1:])) | ||
253 | self.out.nl() | ||