blob: dff176238eba3ce69b30a00508152b7f0e393e73 [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",
Gavin Makea2e3302023-03-11 06:46:20 +000040 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 Hansche2f127de2012-07-09 12:59:56 -040056
Gavin Makea2e3302023-03-11 06:46:20 +000057 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 Hansche2f127de2012-07-09 12:59:56 -040067
Gavin Makea2e3302023-03-11 06:46:20 +000068 if not all_branches:
69 return
Joe Hansche2f127de2012-07-09 12:59:56 -040070
Gavin Makea2e3302023-03-11 06:46:20 +000071 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 Hansche2f127de2012-07-09 12:59:56 -040076
Gavin Makea2e3302023-03-11 06:46:20 +000077 out = Report(all_branches[0].project.config)
78 out.text("Deprecated. See repo info -o.")
Joe Hansche2f127de2012-07-09 12:59:56 -040079 out.nl()
Gavin Makea2e3302023-03-11 06:46:20 +000080 out.project("Projects Overview")
Joe Hansche2f127de2012-07-09 12:59:56 -040081 out.nl()
82
Gavin Makea2e3302023-03-11 06:46:20 +000083 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))