blob: b1e92e3e44cafa8e5839cc5cb13192e30b82e5ca [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
Mike Frysinger31067c02019-06-13 02:13:23 -0400106 localBranches = list(p.GetBranches().keys())
Olof Johansson33949c32012-07-10 14:32:23 +0200107 self.heading("Local Branches: ")
108 self.redtext(str(len(localBranches)))
Mike Frysingerf1c5dd82019-10-01 01:17:55 -0400109 if localBranches:
Olof Johansson33949c32012-07-10 14:32:23 +0200110 self.text(" [")
111 self.text(", ".join(localBranches))
112 self.text("]")
113 self.out.nl()
114
115 if self.opt.all:
116 self.findRemoteLocalDiff(p)
117
118 self.printSeparator()
119
120 def findRemoteLocalDiff(self, project):
121 #Fetch all the latest commits
122 if not self.opt.local:
123 project.Sync_NetworkHalf(quiet=True, current_branch_only=True)
124
Olof Johansson57bd7b72013-01-29 08:22:05 +0100125 logTarget = R_M + self.manifest.manifestProject.config.GetBranch("default").merge
Olof Johansson33949c32012-07-10 14:32:23 +0200126
127 bareTmp = project.bare_git._bare
128 project.bare_git._bare = False
129 localCommits = project.bare_git.rev_list(
130 '--abbrev=8',
131 '--abbrev-commit',
132 '--pretty=oneline',
133 logTarget + "..",
134 '--')
135
136 originCommits = project.bare_git.rev_list(
137 '--abbrev=8',
138 '--abbrev-commit',
139 '--pretty=oneline',
140 ".." + logTarget,
141 '--')
142 project.bare_git._bare = bareTmp
143
144 self.heading("Local Commits: ")
145 self.redtext(str(len(localCommits)))
146 self.dimtext(" (on current branch)")
147 self.out.nl()
148
149 for c in localCommits:
150 split = c.split()
151 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900152 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200153 self.out.nl()
154
155 self.printSeparator()
156
157 self.heading("Remote Commits: ")
158 self.redtext(str(len(originCommits)))
159 self.out.nl()
160
161 for c in originCommits:
162 split = c.split()
163 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900164 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200165 self.out.nl()
166
167 def printCommitOverview(self, args):
168 all_branches = []
169 for project in self.GetProjects(args):
170 br = [project.GetUploadableBranch(x)
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530171 for x in project.GetBranches()]
Olof Johansson33949c32012-07-10 14:32:23 +0200172 br = [x for x in br if x]
173 if self.opt.current_branch:
174 br = [x for x in br if x.name == project.CurrentBranch]
175 all_branches.extend(br)
176
177 if not all_branches:
178 return
179
180 self.out.nl()
181 self.heading('Projects Overview')
182 project = None
183
184 for branch in all_branches:
185 if project != branch.project:
186 project = branch.project
187 self.out.nl()
188 self.headtext(project.relpath)
189 self.out.nl()
190
191 commits = branch.commits
192 date = branch.date
193 self.text('%s %-33s (%2d commit%s, %s)' % (
194 branch.name == project.CurrentBranch and '*' or ' ',
195 branch.name,
196 len(commits),
197 len(commits) != 1 and 's' or '',
198 date))
199 self.out.nl()
200
201 for commit in commits:
202 split = commit.split()
203 self.text('{0:38}{1} '.format('','-'))
204 self.sha(split[0] + " ")
David Pursehousee0b6de32012-11-21 17:36:28 +0900205 self.text(" ".join(split[1:]))
Olof Johansson33949c32012-07-10 14:32:23 +0200206 self.out.nl()