blob: 3a25e3b55b8e8f07a33ad298b74b2863587052d4 [file] [log] [blame]
Olof Johansson33949c32012-07-10 14:32:23 +02001#
2# Copyright (C) 2012 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from command import PagedCommand
17from color import Coloring
18from error import NoSuchProjectError
19from git_refs import R_M
20
21class _Coloring(Coloring):
22 def __init__(self, config):
23 Coloring.__init__(self, config, "status")
24
25class Info(PagedCommand):
26 common = True
27 helpSummary = "Get info on the manifest branch, current branch or unmerged branches"
28 helpUsage = "%prog [-dl] [-o [-b]] [<project>...]"
29
30 def _Options(self, p, show_smart=True):
31 p.add_option('-d', '--diff',
32 dest='all', action='store_true',
33 help="show full info and commit diff including remote branches")
34 p.add_option('-o', '--overview',
35 dest='overview', action='store_true',
36 help='show overview of all local commits')
37 p.add_option('-b', '--current-branch',
38 dest="current_branch", action="store_true",
39 help="consider only checked out branches")
40 p.add_option('-l', '--local-only',
41 dest="local", action="store_true",
42 help="Disable all remote operations")
43
44
45 def Execute(self, opt, args):
46 self.out = _Coloring(self.manifest.globalConfig)
47 self.heading = self.out.printer('heading', attr = 'bold')
48 self.headtext = self.out.printer('headtext', fg = 'yellow')
49 self.redtext = self.out.printer('redtext', fg = 'red')
50 self.sha = self.out.printer("sha", fg = 'yellow')
51 self.text = self.out.printer('text')
52 self.dimtext = self.out.printer('dimtext', attr = 'dim')
53
54 self.opt = opt
55
56 mergeBranch = self.manifest.manifestProject.config.GetBranch("default").merge
57
58 self.heading("Manifest branch: ")
59 self.headtext(self.manifest.default.revisionExpr)
60 self.out.nl()
61 self.heading("Manifest merge branch: ")
62 self.headtext(mergeBranch)
63 self.out.nl()
64
65 self.printSeparator()
66
67 if not opt.overview:
68 self.printDiffInfo(args)
69 else:
70 self.printCommitOverview(args)
71
72 def printSeparator(self):
73 self.text("----------------------------")
74 self.out.nl()
75
76 def printDiffInfo(self, args):
77 try:
78 projs = self.GetProjects(args)
79 except NoSuchProjectError:
80 return
81
82 for p in projs:
83 self.heading("Project: ")
84 self.headtext(p.name)
85 self.out.nl()
86
87 self.heading("Mount path: ")
88 self.headtext(p.worktree)
89 self.out.nl()
90
91 self.heading("Current revision: ")
92 self.headtext(p.revisionExpr)
93 self.out.nl()
94
95 localBranches = p.GetBranches().keys()
96 self.heading("Local Branches: ")
97 self.redtext(str(len(localBranches)))
98 if len(localBranches) > 0:
99 self.text(" [")
100 self.text(", ".join(localBranches))
101 self.text("]")
102 self.out.nl()
103
104 if self.opt.all:
105 self.findRemoteLocalDiff(p)
106
107 self.printSeparator()
108
109 def findRemoteLocalDiff(self, project):
110 #Fetch all the latest commits
111 if not self.opt.local:
112 project.Sync_NetworkHalf(quiet=True, current_branch_only=True)
113
114 logTarget = R_M + self.manifest.default.revisionExpr
115
116 bareTmp = project.bare_git._bare
117 project.bare_git._bare = False
118 localCommits = project.bare_git.rev_list(
119 '--abbrev=8',
120 '--abbrev-commit',
121 '--pretty=oneline',
122 logTarget + "..",
123 '--')
124
125 originCommits = project.bare_git.rev_list(
126 '--abbrev=8',
127 '--abbrev-commit',
128 '--pretty=oneline',
129 ".." + logTarget,
130 '--')
131 project.bare_git._bare = bareTmp
132
133 self.heading("Local Commits: ")
134 self.redtext(str(len(localCommits)))
135 self.dimtext(" (on current branch)")
136 self.out.nl()
137
138 for c in localCommits:
139 split = c.split()
140 self.sha(split[0] + " ")
141 self.text("".join(split[1:]))
142 self.out.nl()
143
144 self.printSeparator()
145
146 self.heading("Remote Commits: ")
147 self.redtext(str(len(originCommits)))
148 self.out.nl()
149
150 for c in originCommits:
151 split = c.split()
152 self.sha(split[0] + " ")
153 self.text("".join(split[1:]))
154 self.out.nl()
155
156 def printCommitOverview(self, args):
157 all_branches = []
158 for project in self.GetProjects(args):
159 br = [project.GetUploadableBranch(x)
160 for x in project.GetBranches().keys()]
161 br = [x for x in br if x]
162 if self.opt.current_branch:
163 br = [x for x in br if x.name == project.CurrentBranch]
164 all_branches.extend(br)
165
166 if not all_branches:
167 return
168
169 self.out.nl()
170 self.heading('Projects Overview')
171 project = None
172
173 for branch in all_branches:
174 if project != branch.project:
175 project = branch.project
176 self.out.nl()
177 self.headtext(project.relpath)
178 self.out.nl()
179
180 commits = branch.commits
181 date = branch.date
182 self.text('%s %-33s (%2d commit%s, %s)' % (
183 branch.name == project.CurrentBranch and '*' or ' ',
184 branch.name,
185 len(commits),
186 len(commits) != 1 and 's' or '',
187 date))
188 self.out.nl()
189
190 for commit in commits:
191 split = commit.split()
192 self.text('{0:38}{1} '.format('','-'))
193 self.sha(split[0] + " ")
194 self.text("".join(split[1:]))
195 self.out.nl()