blob: a9ad52aac428ecaef42809e8909c5bb678b5b0de [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
Olof Johansson33949c32012-07-10 14:32:23 +020019from 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
David Pursehouseda45e5d2013-05-15 17:34:45 +090030 def _Options(self, p):
Olof Johansson33949c32012-07-10 14:32:23 +020031 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')
Sebastian Schuberth266f74c2019-04-17 19:08:52 +020048 self.headtext = self.out.nofmt_printer('headtext', fg = 'yellow')
Olof Johansson33949c32012-07-10 14:32:23 +020049 self.redtext = self.out.printer('redtext', fg = 'red')
50 self.sha = self.out.printer("sha", fg = 'yellow')
Olof Johansson75b4c2d2013-02-18 13:18:16 +010051 self.text = self.out.nofmt_printer('text')
Olof Johansson33949c32012-07-10 14:32:23 +020052 self.dimtext = self.out.printer('dimtext', attr = 'dim')
53
54 self.opt = opt
55
Conley Owens61ac9ae2013-03-05 10:35:36 -080056 manifestConfig = self.manifest.manifestProject.config
57 mergeBranch = manifestConfig.GetBranch("default").merge
58 manifestGroups = (manifestConfig.GetString('manifest.groups')
59 or 'all,-notdefault')
Olof Johansson33949c32012-07-10 14:32:23 +020060
61 self.heading("Manifest branch: ")
Cassidy Burden17af5782015-06-29 14:51:35 -070062 if self.manifest.default.revisionExpr:
63 self.headtext(self.manifest.default.revisionExpr)
Olof Johansson33949c32012-07-10 14:32:23 +020064 self.out.nl()
65 self.heading("Manifest merge branch: ")
66 self.headtext(mergeBranch)
67 self.out.nl()
Conley Owens61ac9ae2013-03-05 10:35:36 -080068 self.heading("Manifest groups: ")
69 self.headtext(manifestGroups)
70 self.out.nl()
Olof Johansson33949c32012-07-10 14:32:23 +020071
72 self.printSeparator()
73
74 if not opt.overview:
75 self.printDiffInfo(args)
76 else:
77 self.printCommitOverview(args)
78
79 def printSeparator(self):
80 self.text("----------------------------")
81 self.out.nl()
82
83 def printDiffInfo(self, args):
Mike Frysinger9775a3d2019-10-01 01:01:33 -040084 # We let exceptions bubble up to main as they'll be well structured.
85 projs = self.GetProjects(args)
Olof Johansson33949c32012-07-10 14:32:23 +020086
87 for p in projs:
88 self.heading("Project: ")
89 self.headtext(p.name)
90 self.out.nl()
91
92 self.heading("Mount path: ")
93 self.headtext(p.worktree)
94 self.out.nl()
95
96 self.heading("Current revision: ")
Mike Frysingerf1c5dd82019-10-01 01:17:55 -040097 self.headtext(p.GetRevisionId())
Olof Johansson33949c32012-07-10 14:32:23 +020098 self.out.nl()
99
Mike Frysingerf1c5dd82019-10-01 01:17:55 -0400100 currentBranch = p.CurrentBranch
101 if currentBranch:
102 self.heading('Current branch: ')
103 self.headtext(currentBranch)
104 self.out.nl()
105
Diogo Ferreirae4d20372019-10-14 16:28:46 +0100106 self.heading("Manifest revision: ")
107 self.headtext(p.revisionExpr)
108 self.out.nl()
109
Mike Frysinger31067c02019-06-13 02:13:23 -0400110 localBranches = list(p.GetBranches().keys())
Olof Johansson33949c32012-07-10 14:32:23 +0200111 self.heading("Local Branches: ")
112 self.redtext(str(len(localBranches)))
Mike Frysingerf1c5dd82019-10-01 01:17:55 -0400113 if localBranches:
Olof Johansson33949c32012-07-10 14:32:23 +0200114 self.text(" [")
115 self.text(", ".join(localBranches))
116 self.text("]")
117 self.out.nl()
118
119 if self.opt.all:
120 self.findRemoteLocalDiff(p)
121
122 self.printSeparator()
123
124 def findRemoteLocalDiff(self, project):
David Pursehouse719675b2020-02-12 11:46:45 +0900125 # Fetch all the latest commits.
Olof Johansson33949c32012-07-10 14:32:23 +0200126 if not self.opt.local:
127 project.Sync_NetworkHalf(quiet=True, current_branch_only=True)
128
Olof Johansson57bd7b72013-01-29 08:22:05 +0100129 logTarget = R_M + self.manifest.manifestProject.config.GetBranch("default").merge
Olof Johansson33949c32012-07-10 14:32:23 +0200130
131 bareTmp = project.bare_git._bare
132 project.bare_git._bare = False
133 localCommits = project.bare_git.rev_list(
134 '--abbrev=8',
135 '--abbrev-commit',
136 '--pretty=oneline',
137 logTarget + "..",
138 '--')
139
140 originCommits = project.bare_git.rev_list(
141 '--abbrev=8',
142 '--abbrev-commit',
143 '--pretty=oneline',
144 ".." + logTarget,
145 '--')
146 project.bare_git._bare = bareTmp
147
148 self.heading("Local Commits: ")
149 self.redtext(str(len(localCommits)))
150 self.dimtext(" (on current branch)")
151 self.out.nl()
152
153 for c in localCommits:
154 split = c.split()
155 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900156 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200157 self.out.nl()
158
159 self.printSeparator()
160
161 self.heading("Remote Commits: ")
162 self.redtext(str(len(originCommits)))
163 self.out.nl()
164
165 for c in originCommits:
166 split = c.split()
167 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900168 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200169 self.out.nl()
170
171 def printCommitOverview(self, args):
172 all_branches = []
173 for project in self.GetProjects(args):
174 br = [project.GetUploadableBranch(x)
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530175 for x in project.GetBranches()]
Olof Johansson33949c32012-07-10 14:32:23 +0200176 br = [x for x in br if x]
177 if self.opt.current_branch:
178 br = [x for x in br if x.name == project.CurrentBranch]
179 all_branches.extend(br)
180
181 if not all_branches:
182 return
183
184 self.out.nl()
185 self.heading('Projects Overview')
186 project = None
187
188 for branch in all_branches:
189 if project != branch.project:
190 project = branch.project
191 self.out.nl()
192 self.headtext(project.relpath)
193 self.out.nl()
194
195 commits = branch.commits
196 date = branch.date
197 self.text('%s %-33s (%2d commit%s, %s)' % (
198 branch.name == project.CurrentBranch and '*' or ' ',
199 branch.name,
200 len(commits),
201 len(commits) != 1 and 's' or '',
202 date))
203 self.out.nl()
204
205 for commit in commits:
206 split = commit.split()
207 self.text('{0:38}{1} '.format('','-'))
208 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900209 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200210 self.out.nl()