blob: 202a5ebad486ab47f9a8463a8e3c9699e6d3b2cc [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 Frysinger73561142021-05-03 01:10:09 -040040 p.add_option('--no-current-branch',
41 dest='current_branch', action='store_false',
42 help='consider all local branches')
Mike Frysingerb8e09ea2021-05-03 00:51:52 -040043 # Turn this into a warning & remove this someday.
44 p.add_option('-b',
45 dest='current_branch', action='store_true',
46 help=optparse.SUPPRESS_HELP)
Joe Hansche2f127de2012-07-09 12:59:56 -040047
48 def Execute(self, opt, args):
David Pursehouse8a68ff92012-09-24 12:15:13 +090049 all_branches = []
Joe Hansche2f127de2012-07-09 12:59:56 -040050 for project in self.GetProjects(args):
51 br = [project.GetUploadableBranch(x)
Chirayu Desai217ea7d2013-03-01 19:14:38 +053052 for x in project.GetBranches()]
Joe Hansche2f127de2012-07-09 12:59:56 -040053 br = [x for x in br if x]
54 if opt.current_branch:
55 br = [x for x in br if x.name == project.CurrentBranch]
David Pursehouse8a68ff92012-09-24 12:15:13 +090056 all_branches.extend(br)
Joe Hansche2f127de2012-07-09 12:59:56 -040057
David Pursehouse8a68ff92012-09-24 12:15:13 +090058 if not all_branches:
Joe Hansche2f127de2012-07-09 12:59:56 -040059 return
60
61 class Report(Coloring):
62 def __init__(self, config):
63 Coloring.__init__(self, config, 'status')
64 self.project = self.printer('header', attr='bold')
Olof Johansson33949c32012-07-10 14:32:23 +020065 self.text = self.printer('text')
Joe Hansche2f127de2012-07-09 12:59:56 -040066
David Pursehouse8a68ff92012-09-24 12:15:13 +090067 out = Report(all_branches[0].project.config)
Olof Johansson33949c32012-07-10 14:32:23 +020068 out.text("Deprecated. See repo info -o.")
69 out.nl()
Joe Hansche2f127de2012-07-09 12:59:56 -040070 out.project('Projects Overview')
71 out.nl()
72
73 project = None
74
David Pursehouse8a68ff92012-09-24 12:15:13 +090075 for branch in all_branches:
Joe Hansche2f127de2012-07-09 12:59:56 -040076 if project != branch.project:
77 project = branch.project
78 out.nl()
79 out.project('project %s/' % project.relpath)
80 out.nl()
81
82 commits = branch.commits
83 date = branch.date
Sarah Owenscecd1d82012-11-01 22:59:27 -070084 print('%s %-33s (%2d commit%s, %s)' % (
Joe Hansche2f127de2012-07-09 12:59:56 -040085 branch.name == project.CurrentBranch and '*' or ' ',
86 branch.name,
87 len(commits),
88 len(commits) != 1 and 's' or ' ',
Sarah Owenscecd1d82012-11-01 22:59:27 -070089 date))
Joe Hansche2f127de2012-07-09 12:59:56 -040090 for commit in commits:
Sarah Owenscecd1d82012-11-01 22:59:27 -070091 print('%-35s - %s' % ('', commit))