blob: 004a847c0e579550290d5b7defd1e0074fc4ad52 [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
15from color import Coloring
16from command import PagedCommand
17
18
19class Overview(PagedCommand):
20 common = True
21 helpSummary = "Display overview of unmerged project branches"
22 helpUsage = """
23%prog [--current-branch] [<project>...]
24"""
25 helpDescription = """
26The '%prog' command is used to display an overview of the projects branches,
27and list any local commits that have not yet been merged into the project.
28
29The -b/--current-branch option can be used to restrict the output to only
30branches currently checked out in each project. By default, all branches
31are displayed.
32"""
33
34 def _Options(self, p):
35 p.add_option('-b', '--current-branch',
36 dest="current_branch", action="store_true",
37 help="Consider only checked out branches")
38
39 def Execute(self, opt, args):
David Pursehouse8a68ff92012-09-24 12:15:13 +090040 all_branches = []
Joe Hansche2f127de2012-07-09 12:59:56 -040041 for project in self.GetProjects(args):
42 br = [project.GetUploadableBranch(x)
Chirayu Desai217ea7d2013-03-01 19:14:38 +053043 for x in project.GetBranches()]
Joe Hansche2f127de2012-07-09 12:59:56 -040044 br = [x for x in br if x]
45 if opt.current_branch:
46 br = [x for x in br if x.name == project.CurrentBranch]
David Pursehouse8a68ff92012-09-24 12:15:13 +090047 all_branches.extend(br)
Joe Hansche2f127de2012-07-09 12:59:56 -040048
David Pursehouse8a68ff92012-09-24 12:15:13 +090049 if not all_branches:
Joe Hansche2f127de2012-07-09 12:59:56 -040050 return
51
52 class Report(Coloring):
53 def __init__(self, config):
54 Coloring.__init__(self, config, 'status')
55 self.project = self.printer('header', attr='bold')
Olof Johansson33949c32012-07-10 14:32:23 +020056 self.text = self.printer('text')
Joe Hansche2f127de2012-07-09 12:59:56 -040057
David Pursehouse8a68ff92012-09-24 12:15:13 +090058 out = Report(all_branches[0].project.config)
Olof Johansson33949c32012-07-10 14:32:23 +020059 out.text("Deprecated. See repo info -o.")
60 out.nl()
Joe Hansche2f127de2012-07-09 12:59:56 -040061 out.project('Projects Overview')
62 out.nl()
63
64 project = None
65
David Pursehouse8a68ff92012-09-24 12:15:13 +090066 for branch in all_branches:
Joe Hansche2f127de2012-07-09 12:59:56 -040067 if project != branch.project:
68 project = branch.project
69 out.nl()
70 out.project('project %s/' % project.relpath)
71 out.nl()
72
73 commits = branch.commits
74 date = branch.date
Sarah Owenscecd1d82012-11-01 22:59:27 -070075 print('%s %-33s (%2d commit%s, %s)' % (
Joe Hansche2f127de2012-07-09 12:59:56 -040076 branch.name == project.CurrentBranch and '*' or ' ',
77 branch.name,
78 len(commits),
79 len(commits) != 1 and 's' or ' ',
Sarah Owenscecd1d82012-11-01 22:59:27 -070080 date))
Joe Hansche2f127de2012-07-09 12:59:56 -040081 for commit in commits:
Sarah Owenscecd1d82012-11-01 22:59:27 -070082 print('%-35s - %s' % ('', commit))