blob: be5a8f2ae21fa76a8929732254b79792c99d3817 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
Olof Johansson33949c32012-07-10 14:32:23 +02002#
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
17from command import PagedCommand
18from color import Coloring
19from error import NoSuchProjectError
20from git_refs import R_M
21
22class _Coloring(Coloring):
23 def __init__(self, config):
24 Coloring.__init__(self, config, "status")
25
26class Info(PagedCommand):
27 common = True
28 helpSummary = "Get info on the manifest branch, current branch or unmerged branches"
29 helpUsage = "%prog [-dl] [-o [-b]] [<project>...]"
30
David Pursehouseda45e5d2013-05-15 17:34:45 +090031 def _Options(self, p):
Olof Johansson33949c32012-07-10 14:32:23 +020032 p.add_option('-d', '--diff',
33 dest='all', action='store_true',
34 help="show full info and commit diff including remote branches")
35 p.add_option('-o', '--overview',
36 dest='overview', action='store_true',
37 help='show overview of all local commits')
38 p.add_option('-b', '--current-branch',
39 dest="current_branch", action="store_true",
40 help="consider only checked out branches")
41 p.add_option('-l', '--local-only',
42 dest="local", action="store_true",
43 help="Disable all remote operations")
44
45
46 def Execute(self, opt, args):
47 self.out = _Coloring(self.manifest.globalConfig)
48 self.heading = self.out.printer('heading', attr = 'bold')
Sebastian Schuberth266f74c2019-04-17 19:08:52 +020049 self.headtext = self.out.nofmt_printer('headtext', fg = 'yellow')
Olof Johansson33949c32012-07-10 14:32:23 +020050 self.redtext = self.out.printer('redtext', fg = 'red')
51 self.sha = self.out.printer("sha", fg = 'yellow')
Olof Johansson75b4c2d2013-02-18 13:18:16 +010052 self.text = self.out.nofmt_printer('text')
Olof Johansson33949c32012-07-10 14:32:23 +020053 self.dimtext = self.out.printer('dimtext', attr = 'dim')
54
55 self.opt = opt
56
Conley Owens61ac9ae2013-03-05 10:35:36 -080057 manifestConfig = self.manifest.manifestProject.config
58 mergeBranch = manifestConfig.GetBranch("default").merge
59 manifestGroups = (manifestConfig.GetString('manifest.groups')
60 or 'all,-notdefault')
Olof Johansson33949c32012-07-10 14:32:23 +020061
62 self.heading("Manifest branch: ")
Cassidy Burden17af5782015-06-29 14:51:35 -070063 if self.manifest.default.revisionExpr:
64 self.headtext(self.manifest.default.revisionExpr)
Olof Johansson33949c32012-07-10 14:32:23 +020065 self.out.nl()
66 self.heading("Manifest merge branch: ")
67 self.headtext(mergeBranch)
68 self.out.nl()
Conley Owens61ac9ae2013-03-05 10:35:36 -080069 self.heading("Manifest groups: ")
70 self.headtext(manifestGroups)
71 self.out.nl()
Olof Johansson33949c32012-07-10 14:32:23 +020072
73 self.printSeparator()
74
75 if not opt.overview:
76 self.printDiffInfo(args)
77 else:
78 self.printCommitOverview(args)
79
80 def printSeparator(self):
81 self.text("----------------------------")
82 self.out.nl()
83
84 def printDiffInfo(self, args):
85 try:
86 projs = self.GetProjects(args)
87 except NoSuchProjectError:
88 return
89
90 for p in projs:
91 self.heading("Project: ")
92 self.headtext(p.name)
93 self.out.nl()
94
95 self.heading("Mount path: ")
96 self.headtext(p.worktree)
97 self.out.nl()
98
99 self.heading("Current revision: ")
100 self.headtext(p.revisionExpr)
101 self.out.nl()
102
Mike Frysinger31067c02019-06-13 02:13:23 -0400103 localBranches = list(p.GetBranches().keys())
Olof Johansson33949c32012-07-10 14:32:23 +0200104 self.heading("Local Branches: ")
105 self.redtext(str(len(localBranches)))
106 if len(localBranches) > 0:
107 self.text(" [")
108 self.text(", ".join(localBranches))
109 self.text("]")
110 self.out.nl()
111
112 if self.opt.all:
113 self.findRemoteLocalDiff(p)
114
115 self.printSeparator()
116
117 def findRemoteLocalDiff(self, project):
118 #Fetch all the latest commits
119 if not self.opt.local:
120 project.Sync_NetworkHalf(quiet=True, current_branch_only=True)
121
Olof Johansson57bd7b72013-01-29 08:22:05 +0100122 logTarget = R_M + self.manifest.manifestProject.config.GetBranch("default").merge
Olof Johansson33949c32012-07-10 14:32:23 +0200123
124 bareTmp = project.bare_git._bare
125 project.bare_git._bare = False
126 localCommits = project.bare_git.rev_list(
127 '--abbrev=8',
128 '--abbrev-commit',
129 '--pretty=oneline',
130 logTarget + "..",
131 '--')
132
133 originCommits = project.bare_git.rev_list(
134 '--abbrev=8',
135 '--abbrev-commit',
136 '--pretty=oneline',
137 ".." + logTarget,
138 '--')
139 project.bare_git._bare = bareTmp
140
141 self.heading("Local Commits: ")
142 self.redtext(str(len(localCommits)))
143 self.dimtext(" (on current branch)")
144 self.out.nl()
145
146 for c in localCommits:
147 split = c.split()
148 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900149 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200150 self.out.nl()
151
152 self.printSeparator()
153
154 self.heading("Remote Commits: ")
155 self.redtext(str(len(originCommits)))
156 self.out.nl()
157
158 for c in originCommits:
159 split = c.split()
160 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900161 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200162 self.out.nl()
163
164 def printCommitOverview(self, args):
165 all_branches = []
166 for project in self.GetProjects(args):
167 br = [project.GetUploadableBranch(x)
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530168 for x in project.GetBranches()]
Olof Johansson33949c32012-07-10 14:32:23 +0200169 br = [x for x in br if x]
170 if self.opt.current_branch:
171 br = [x for x in br if x.name == project.CurrentBranch]
172 all_branches.extend(br)
173
174 if not all_branches:
175 return
176
177 self.out.nl()
178 self.heading('Projects Overview')
179 project = None
180
181 for branch in all_branches:
182 if project != branch.project:
183 project = branch.project
184 self.out.nl()
185 self.headtext(project.relpath)
186 self.out.nl()
187
188 commits = branch.commits
189 date = branch.date
190 self.text('%s %-33s (%2d commit%s, %s)' % (
191 branch.name == project.CurrentBranch and '*' or ' ',
192 branch.name,
193 len(commits),
194 len(commits) != 1 and 's' or '',
195 date))
196 self.out.nl()
197
198 for commit in commits:
199 split = commit.split()
200 self.text('{0:38}{1} '.format('','-'))
201 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900202 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200203 self.out.nl()