blob: 4f62f94f5a59a267c3758d8d2389a0f77de263fe [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):
22 common = True
23 helpSummary = "Display overview of unmerged project branches"
24 helpUsage = """
25%prog [--current-branch] [<project>...]
26"""
27 helpDescription = """
28The '%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
36 def _Options(self, p):
Mike Frysingerb8e09ea2021-05-03 00:51:52 -040037 p.add_option('-c', '--current-branch',
Joe Hansche2f127de2012-07-09 12:59:56 -040038 dest="current_branch", action="store_true",
39 help="Consider only checked out branches")
Mike Frysingerb8e09ea2021-05-03 00:51:52 -040040 # Turn this into a warning & remove this someday.
41 p.add_option('-b',
42 dest='current_branch', action='store_true',
43 help=optparse.SUPPRESS_HELP)
Joe Hansche2f127de2012-07-09 12:59:56 -040044
45 def Execute(self, opt, args):
David Pursehouse8a68ff92012-09-24 12:15:13 +090046 all_branches = []
Joe Hansche2f127de2012-07-09 12:59:56 -040047 for project in self.GetProjects(args):
48 br = [project.GetUploadableBranch(x)
Chirayu Desai217ea7d2013-03-01 19:14:38 +053049 for x in project.GetBranches()]
Joe Hansche2f127de2012-07-09 12:59:56 -040050 br = [x for x in br if x]
51 if opt.current_branch:
52 br = [x for x in br if x.name == project.CurrentBranch]
David Pursehouse8a68ff92012-09-24 12:15:13 +090053 all_branches.extend(br)
Joe Hansche2f127de2012-07-09 12:59:56 -040054
David Pursehouse8a68ff92012-09-24 12:15:13 +090055 if not all_branches:
Joe Hansche2f127de2012-07-09 12:59:56 -040056 return
57
58 class Report(Coloring):
59 def __init__(self, config):
60 Coloring.__init__(self, config, 'status')
61 self.project = self.printer('header', attr='bold')
Olof Johansson33949c32012-07-10 14:32:23 +020062 self.text = self.printer('text')
Joe Hansche2f127de2012-07-09 12:59:56 -040063
David Pursehouse8a68ff92012-09-24 12:15:13 +090064 out = Report(all_branches[0].project.config)
Olof Johansson33949c32012-07-10 14:32:23 +020065 out.text("Deprecated. See repo info -o.")
66 out.nl()
Joe Hansche2f127de2012-07-09 12:59:56 -040067 out.project('Projects Overview')
68 out.nl()
69
70 project = None
71
David Pursehouse8a68ff92012-09-24 12:15:13 +090072 for branch in all_branches:
Joe Hansche2f127de2012-07-09 12:59:56 -040073 if project != branch.project:
74 project = branch.project
75 out.nl()
76 out.project('project %s/' % project.relpath)
77 out.nl()
78
79 commits = branch.commits
80 date = branch.date
Sarah Owenscecd1d82012-11-01 22:59:27 -070081 print('%s %-33s (%2d commit%s, %s)' % (
Joe Hansche2f127de2012-07-09 12:59:56 -040082 branch.name == project.CurrentBranch and '*' or ' ',
83 branch.name,
84 len(commits),
85 len(commits) != 1 and 's' or ' ',
Sarah Owenscecd1d82012-11-01 22:59:27 -070086 date))
Joe Hansche2f127de2012-07-09 12:59:56 -040087 for commit in commits:
Sarah Owenscecd1d82012-11-01 22:59:27 -070088 print('%-35s - %s' % ('', commit))