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", |
| 40 | dest="current_branch", |
| 41 | action="store_true", |
| 42 | help="consider only checked out branches", |
| 43 | ) |
| 44 | p.add_option( |
| 45 | "--no-current-branch", |
| 46 | dest="current_branch", |
| 47 | action="store_false", |
| 48 | help="consider all local branches", |
| 49 | ) |
| 50 | # Turn this into a warning & remove this someday. |
| 51 | p.add_option( |
| 52 | "-b", |
| 53 | dest="current_branch", |
| 54 | action="store_true", |
| 55 | help=optparse.SUPPRESS_HELP, |
| 56 | ) |
Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 57 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 58 | def Execute(self, opt, args): |
| 59 | all_branches = [] |
| 60 | for project in self.GetProjects( |
| 61 | args, all_manifests=not opt.this_manifest_only |
| 62 | ): |
| 63 | br = [project.GetUploadableBranch(x) for x in project.GetBranches()] |
| 64 | br = [x for x in br if x] |
| 65 | if opt.current_branch: |
| 66 | br = [x for x in br if x.name == project.CurrentBranch] |
| 67 | all_branches.extend(br) |
Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 68 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 69 | if not all_branches: |
| 70 | return |
Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 71 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 72 | class Report(Coloring): |
| 73 | def __init__(self, config): |
| 74 | Coloring.__init__(self, config, "status") |
| 75 | self.project = self.printer("header", attr="bold") |
| 76 | self.text = self.printer("text") |
Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 77 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 78 | out = Report(all_branches[0].project.config) |
| 79 | out.text("Deprecated. See repo info -o.") |
Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 80 | out.nl() |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 81 | out.project("Projects Overview") |
Joe Hansche | 2f127de | 2012-07-09 12:59:56 -0400 | [diff] [blame] | 82 | out.nl() |
| 83 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 84 | project = None |
| 85 | |
| 86 | for branch in all_branches: |
| 87 | if project != branch.project: |
| 88 | project = branch.project |
| 89 | out.nl() |
| 90 | out.project( |
| 91 | "project %s/" |
| 92 | % project.RelPath(local=opt.this_manifest_only) |
| 93 | ) |
| 94 | out.nl() |
| 95 | |
| 96 | commits = branch.commits |
| 97 | date = branch.date |
| 98 | print( |
| 99 | "%s %-33s (%2d commit%s, %s)" |
| 100 | % ( |
| 101 | branch.name == project.CurrentBranch and "*" or " ", |
| 102 | branch.name, |
| 103 | len(commits), |
| 104 | len(commits) != 1 and "s" or " ", |
| 105 | date, |
| 106 | ) |
| 107 | ) |
| 108 | for commit in commits: |
| 109 | print("%-35s - %s" % ("", commit)) |