| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 1 | # Copyright (C) 2012 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| Mike Frysinger | b8e09ea | 2021-05-03 00:51:52 -0400 | [diff] [blame] | 15 | import optparse |
| 16 | |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 17 | from color import Coloring |
| 18 | from command import PagedCommand |
| 19 | |
| 20 | |
| 21 | class Overview(PagedCommand): |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 22 | COMMON = True |
| 23 | helpSummary = "Display overview of unmerged project branches" |
| 24 | helpUsage = """ |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 25 | %prog [--current-branch] [<project>...] |
| 26 | """ |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 27 | helpDescription = """ |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 28 | The '%prog' command is used to display an overview of the projects branches, |
| 29 | and list any local commits that have not yet been merged into the project. |
| 30 | |
| Mike Frysinger | b8e09ea | 2021-05-03 00:51:52 -0400 | [diff] [blame] | 31 | The -c/--current-branch option can be used to restrict the output to only |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 32 | branches currently checked out in each project. By default, all branches |
| 33 | are displayed. |
| 34 | """ |
| 35 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 36 | def _Options(self, p): |
| 37 | p.add_option( |
| 38 | "-c", |
| 39 | "--current-branch", |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 40 | action="store_true", |
| 41 | help="consider only checked out branches", |
| 42 | ) |
| 43 | p.add_option( |
| 44 | "--no-current-branch", |
| 45 | dest="current_branch", |
| 46 | action="store_false", |
| 47 | help="consider all local branches", |
| 48 | ) |
| 49 | # Turn this into a warning & remove this someday. |
| 50 | p.add_option( |
| 51 | "-b", |
| 52 | dest="current_branch", |
| 53 | action="store_true", |
| 54 | help=optparse.SUPPRESS_HELP, |
| 55 | ) |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 56 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 57 | def Execute(self, opt, args): |
| 58 | all_branches = [] |
| 59 | for project in self.GetProjects( |
| 60 | args, all_manifests=not opt.this_manifest_only |
| 61 | ): |
| 62 | br = [project.GetUploadableBranch(x) for x in project.GetBranches()] |
| 63 | br = [x for x in br if x] |
| 64 | if opt.current_branch: |
| 65 | br = [x for x in br if x.name == project.CurrentBranch] |
| 66 | all_branches.extend(br) |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 67 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 68 | if not all_branches: |
| 69 | return |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 70 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 71 | class Report(Coloring): |
| 72 | def __init__(self, config): |
| 73 | Coloring.__init__(self, config, "status") |
| 74 | self.project = self.printer("header", attr="bold") |
| 75 | self.text = self.printer("text") |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 76 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 77 | out = Report(all_branches[0].project.config) |
| 78 | out.text("Deprecated. See repo info -o.") |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 79 | out.nl() |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 80 | out.project("Projects Overview") |
| Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 81 | out.nl() |
| 82 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 83 | project = None |
| 84 | |
| 85 | for branch in all_branches: |
| 86 | if project != branch.project: |
| 87 | project = branch.project |
| 88 | out.nl() |
| 89 | out.project( |
| 90 | "project %s/" |
| 91 | % project.RelPath(local=opt.this_manifest_only) |
| 92 | ) |
| 93 | out.nl() |
| 94 | |
| 95 | commits = branch.commits |
| 96 | date = branch.date |
| 97 | print( |
| 98 | "%s %-33s (%2d commit%s, %s)" |
| 99 | % ( |
| 100 | branch.name == project.CurrentBranch and "*" or " ", |
| 101 | branch.name, |
| 102 | len(commits), |
| 103 | len(commits) != 1 and "s" or " ", |
| 104 | date, |
| 105 | ) |
| 106 | ) |
| 107 | for commit in commits: |
| 108 | print("%-35s - %s" % ("", commit)) |