blob: 8ccad6110a960b74c4b7c8df7899b4838522b110 [file] [log] [blame]
Joe Hansche2f127de2012-07-09 12:59:56 -04001# 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 Frysingerb8e09ea2021-05-03 00:51:52 -040015import optparse
16
Joe Hansche2f127de2012-07-09 12:59:56 -040017from color import Coloring
18from command import PagedCommand
19
20
21class Overview(PagedCommand):
Gavin Makea2e3302023-03-11 06:46:20 +000022 COMMON = True
23 helpSummary = "Display overview of unmerged project branches"
24 helpUsage = """
Joe Hansche2f127de2012-07-09 12:59:56 -040025%prog [--current-branch] [<project>...]
26"""
Gavin Makea2e3302023-03-11 06:46:20 +000027 helpDescription = """
Joe Hansche2f127de2012-07-09 12:59:56 -040028The '%prog' command is used to display an overview of the projects branches,
29and list any local commits that have not yet been merged into the project.
30
Mike Frysingerb8e09ea2021-05-03 00:51:52 -040031The -c/--current-branch option can be used to restrict the output to only
Joe Hansche2f127de2012-07-09 12:59:56 -040032branches currently checked out in each project. By default, all branches
33are displayed.
34"""
35
Gavin Makea2e3302023-03-11 06:46:20 +000036 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 Hansche2f127de2012-07-09 12:59:56 -040057
Gavin Makea2e3302023-03-11 06:46:20 +000058 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 Hansche2f127de2012-07-09 12:59:56 -040068
Gavin Makea2e3302023-03-11 06:46:20 +000069 if not all_branches:
70 return
Joe Hansche2f127de2012-07-09 12:59:56 -040071
Gavin Makea2e3302023-03-11 06:46:20 +000072 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 Hansche2f127de2012-07-09 12:59:56 -040077
Gavin Makea2e3302023-03-11 06:46:20 +000078 out = Report(all_branches[0].project.config)
79 out.text("Deprecated. See repo info -o.")
Joe Hansche2f127de2012-07-09 12:59:56 -040080 out.nl()
Gavin Makea2e3302023-03-11 06:46:20 +000081 out.project("Projects Overview")
Joe Hansche2f127de2012-07-09 12:59:56 -040082 out.nl()
83
Gavin Makea2e3302023-03-11 06:46:20 +000084 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))