blob: 08b58a6cf9bdfff16ec4c304d2f631193f458854 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
Joe Hansche2f127de2012-07-09 12:59:56 -04002#
3# Copyright (C) 2012 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Sarah Owenscecd1d82012-11-01 22:59:27 -070017from __future__ import print_function
Joe Hansche2f127de2012-07-09 12:59:56 -040018from color import Coloring
19from command import PagedCommand
20
21
22class Overview(PagedCommand):
23 common = True
24 helpSummary = "Display overview of unmerged project branches"
25 helpUsage = """
26%prog [--current-branch] [<project>...]
27"""
28 helpDescription = """
29The '%prog' command is used to display an overview of the projects branches,
30and list any local commits that have not yet been merged into the project.
31
32The -b/--current-branch option can be used to restrict the output to only
33branches currently checked out in each project. By default, all branches
34are displayed.
35"""
36
37 def _Options(self, p):
38 p.add_option('-b', '--current-branch',
39 dest="current_branch", action="store_true",
40 help="Consider only checked out branches")
41
42 def Execute(self, opt, args):
David Pursehouse8a68ff92012-09-24 12:15:13 +090043 all_branches = []
Joe Hansche2f127de2012-07-09 12:59:56 -040044 for project in self.GetProjects(args):
45 br = [project.GetUploadableBranch(x)
Chirayu Desai217ea7d2013-03-01 19:14:38 +053046 for x in project.GetBranches()]
Joe Hansche2f127de2012-07-09 12:59:56 -040047 br = [x for x in br if x]
48 if opt.current_branch:
49 br = [x for x in br if x.name == project.CurrentBranch]
David Pursehouse8a68ff92012-09-24 12:15:13 +090050 all_branches.extend(br)
Joe Hansche2f127de2012-07-09 12:59:56 -040051
David Pursehouse8a68ff92012-09-24 12:15:13 +090052 if not all_branches:
Joe Hansche2f127de2012-07-09 12:59:56 -040053 return
54
55 class Report(Coloring):
56 def __init__(self, config):
57 Coloring.__init__(self, config, 'status')
58 self.project = self.printer('header', attr='bold')
Olof Johansson33949c32012-07-10 14:32:23 +020059 self.text = self.printer('text')
Joe Hansche2f127de2012-07-09 12:59:56 -040060
David Pursehouse8a68ff92012-09-24 12:15:13 +090061 out = Report(all_branches[0].project.config)
Olof Johansson33949c32012-07-10 14:32:23 +020062 out.text("Deprecated. See repo info -o.")
63 out.nl()
Joe Hansche2f127de2012-07-09 12:59:56 -040064 out.project('Projects Overview')
65 out.nl()
66
67 project = None
68
David Pursehouse8a68ff92012-09-24 12:15:13 +090069 for branch in all_branches:
Joe Hansche2f127de2012-07-09 12:59:56 -040070 if project != branch.project:
71 project = branch.project
72 out.nl()
73 out.project('project %s/' % project.relpath)
74 out.nl()
75
76 commits = branch.commits
77 date = branch.date
Sarah Owenscecd1d82012-11-01 22:59:27 -070078 print('%s %-33s (%2d commit%s, %s)' % (
Joe Hansche2f127de2012-07-09 12:59:56 -040079 branch.name == project.CurrentBranch and '*' or ' ',
80 branch.name,
81 len(commits),
82 len(commits) != 1 and 's' or ' ',
Sarah Owenscecd1d82012-11-01 22:59:27 -070083 date))
Joe Hansche2f127de2012-07-09 12:59:56 -040084 for commit in commits:
Sarah Owenscecd1d82012-11-01 22:59:27 -070085 print('%-35s - %s' % ('', commit))