2019-06-13 06:30:51 +00:00
|
|
|
# -*- coding:utf-8 -*-
|
2012-07-10 12:32:23 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2012 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
from command import PagedCommand
|
|
|
|
from color import Coloring
|
|
|
|
from git_refs import R_M
|
|
|
|
|
|
|
|
class _Coloring(Coloring):
|
|
|
|
def __init__(self, config):
|
|
|
|
Coloring.__init__(self, config, "status")
|
|
|
|
|
|
|
|
class Info(PagedCommand):
|
|
|
|
common = True
|
|
|
|
helpSummary = "Get info on the manifest branch, current branch or unmerged branches"
|
|
|
|
helpUsage = "%prog [-dl] [-o [-b]] [<project>...]"
|
|
|
|
|
2013-05-15 08:34:45 +00:00
|
|
|
def _Options(self, p):
|
2012-07-10 12:32:23 +00:00
|
|
|
p.add_option('-d', '--diff',
|
|
|
|
dest='all', action='store_true',
|
|
|
|
help="show full info and commit diff including remote branches")
|
|
|
|
p.add_option('-o', '--overview',
|
|
|
|
dest='overview', action='store_true',
|
|
|
|
help='show overview of all local commits')
|
|
|
|
p.add_option('-b', '--current-branch',
|
|
|
|
dest="current_branch", action="store_true",
|
|
|
|
help="consider only checked out branches")
|
|
|
|
p.add_option('-l', '--local-only',
|
|
|
|
dest="local", action="store_true",
|
|
|
|
help="Disable all remote operations")
|
|
|
|
|
|
|
|
|
|
|
|
def Execute(self, opt, args):
|
|
|
|
self.out = _Coloring(self.manifest.globalConfig)
|
2020-02-12 04:56:59 +00:00
|
|
|
self.heading = self.out.printer('heading', attr='bold')
|
|
|
|
self.headtext = self.out.nofmt_printer('headtext', fg='yellow')
|
|
|
|
self.redtext = self.out.printer('redtext', fg='red')
|
|
|
|
self.sha = self.out.printer("sha", fg='yellow')
|
2013-02-18 12:18:16 +00:00
|
|
|
self.text = self.out.nofmt_printer('text')
|
2020-02-12 04:56:59 +00:00
|
|
|
self.dimtext = self.out.printer('dimtext', attr='dim')
|
2012-07-10 12:32:23 +00:00
|
|
|
|
|
|
|
self.opt = opt
|
|
|
|
|
2013-03-05 18:35:36 +00:00
|
|
|
manifestConfig = self.manifest.manifestProject.config
|
|
|
|
mergeBranch = manifestConfig.GetBranch("default").merge
|
|
|
|
manifestGroups = (manifestConfig.GetString('manifest.groups')
|
|
|
|
or 'all,-notdefault')
|
2012-07-10 12:32:23 +00:00
|
|
|
|
|
|
|
self.heading("Manifest branch: ")
|
2015-06-29 21:51:35 +00:00
|
|
|
if self.manifest.default.revisionExpr:
|
|
|
|
self.headtext(self.manifest.default.revisionExpr)
|
2012-07-10 12:32:23 +00:00
|
|
|
self.out.nl()
|
|
|
|
self.heading("Manifest merge branch: ")
|
|
|
|
self.headtext(mergeBranch)
|
|
|
|
self.out.nl()
|
2013-03-05 18:35:36 +00:00
|
|
|
self.heading("Manifest groups: ")
|
|
|
|
self.headtext(manifestGroups)
|
|
|
|
self.out.nl()
|
2012-07-10 12:32:23 +00:00
|
|
|
|
|
|
|
self.printSeparator()
|
|
|
|
|
|
|
|
if not opt.overview:
|
|
|
|
self.printDiffInfo(args)
|
|
|
|
else:
|
|
|
|
self.printCommitOverview(args)
|
|
|
|
|
|
|
|
def printSeparator(self):
|
|
|
|
self.text("----------------------------")
|
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
def printDiffInfo(self, args):
|
2019-10-01 05:01:33 +00:00
|
|
|
# We let exceptions bubble up to main as they'll be well structured.
|
|
|
|
projs = self.GetProjects(args)
|
2012-07-10 12:32:23 +00:00
|
|
|
|
|
|
|
for p in projs:
|
|
|
|
self.heading("Project: ")
|
|
|
|
self.headtext(p.name)
|
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
self.heading("Mount path: ")
|
|
|
|
self.headtext(p.worktree)
|
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
self.heading("Current revision: ")
|
2019-10-01 05:17:55 +00:00
|
|
|
self.headtext(p.GetRevisionId())
|
2012-07-10 12:32:23 +00:00
|
|
|
self.out.nl()
|
|
|
|
|
2019-10-01 05:17:55 +00:00
|
|
|
currentBranch = p.CurrentBranch
|
|
|
|
if currentBranch:
|
|
|
|
self.heading('Current branch: ')
|
|
|
|
self.headtext(currentBranch)
|
|
|
|
self.out.nl()
|
|
|
|
|
2019-10-14 15:28:46 +00:00
|
|
|
self.heading("Manifest revision: ")
|
|
|
|
self.headtext(p.revisionExpr)
|
|
|
|
self.out.nl()
|
|
|
|
|
2019-06-13 06:13:23 +00:00
|
|
|
localBranches = list(p.GetBranches().keys())
|
2012-07-10 12:32:23 +00:00
|
|
|
self.heading("Local Branches: ")
|
|
|
|
self.redtext(str(len(localBranches)))
|
2019-10-01 05:17:55 +00:00
|
|
|
if localBranches:
|
2012-07-10 12:32:23 +00:00
|
|
|
self.text(" [")
|
|
|
|
self.text(", ".join(localBranches))
|
|
|
|
self.text("]")
|
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
if self.opt.all:
|
|
|
|
self.findRemoteLocalDiff(p)
|
|
|
|
|
|
|
|
self.printSeparator()
|
|
|
|
|
|
|
|
def findRemoteLocalDiff(self, project):
|
2020-02-12 02:46:45 +00:00
|
|
|
# Fetch all the latest commits.
|
2012-07-10 12:32:23 +00:00
|
|
|
if not self.opt.local:
|
|
|
|
project.Sync_NetworkHalf(quiet=True, current_branch_only=True)
|
|
|
|
|
2013-01-29 07:22:05 +00:00
|
|
|
logTarget = R_M + self.manifest.manifestProject.config.GetBranch("default").merge
|
2012-07-10 12:32:23 +00:00
|
|
|
|
|
|
|
bareTmp = project.bare_git._bare
|
|
|
|
project.bare_git._bare = False
|
|
|
|
localCommits = project.bare_git.rev_list(
|
|
|
|
'--abbrev=8',
|
|
|
|
'--abbrev-commit',
|
|
|
|
'--pretty=oneline',
|
|
|
|
logTarget + "..",
|
|
|
|
'--')
|
|
|
|
|
|
|
|
originCommits = project.bare_git.rev_list(
|
|
|
|
'--abbrev=8',
|
|
|
|
'--abbrev-commit',
|
|
|
|
'--pretty=oneline',
|
|
|
|
".." + logTarget,
|
|
|
|
'--')
|
|
|
|
project.bare_git._bare = bareTmp
|
|
|
|
|
|
|
|
self.heading("Local Commits: ")
|
|
|
|
self.redtext(str(len(localCommits)))
|
|
|
|
self.dimtext(" (on current branch)")
|
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
for c in localCommits:
|
|
|
|
split = c.split()
|
|
|
|
self.sha(split[0] + " ")
|
2012-11-21 08:36:28 +00:00
|
|
|
self.text(" ".join(split[1:]))
|
2012-07-10 12:32:23 +00:00
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
self.printSeparator()
|
|
|
|
|
|
|
|
self.heading("Remote Commits: ")
|
|
|
|
self.redtext(str(len(originCommits)))
|
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
for c in originCommits:
|
|
|
|
split = c.split()
|
|
|
|
self.sha(split[0] + " ")
|
2012-11-21 08:36:28 +00:00
|
|
|
self.text(" ".join(split[1:]))
|
2012-07-10 12:32:23 +00:00
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
def printCommitOverview(self, args):
|
|
|
|
all_branches = []
|
|
|
|
for project in self.GetProjects(args):
|
|
|
|
br = [project.GetUploadableBranch(x)
|
2013-03-01 13:44:38 +00:00
|
|
|
for x in project.GetBranches()]
|
2012-07-10 12:32:23 +00:00
|
|
|
br = [x for x in br if x]
|
|
|
|
if self.opt.current_branch:
|
|
|
|
br = [x for x in br if x.name == project.CurrentBranch]
|
|
|
|
all_branches.extend(br)
|
|
|
|
|
|
|
|
if not all_branches:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.out.nl()
|
|
|
|
self.heading('Projects Overview')
|
|
|
|
project = None
|
|
|
|
|
|
|
|
for branch in all_branches:
|
|
|
|
if project != branch.project:
|
|
|
|
project = branch.project
|
|
|
|
self.out.nl()
|
|
|
|
self.headtext(project.relpath)
|
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
commits = branch.commits
|
|
|
|
date = branch.date
|
|
|
|
self.text('%s %-33s (%2d commit%s, %s)' % (
|
|
|
|
branch.name == project.CurrentBranch and '*' or ' ',
|
|
|
|
branch.name,
|
|
|
|
len(commits),
|
|
|
|
len(commits) != 1 and 's' or '',
|
|
|
|
date))
|
|
|
|
self.out.nl()
|
|
|
|
|
|
|
|
for commit in commits:
|
|
|
|
split = commit.split()
|
|
|
|
self.text('{0:38}{1} '.format('','-'))
|
|
|
|
self.sha(split[0] + " ")
|
2012-11-21 08:36:28 +00:00
|
|
|
self.text(" ".join(split[1:]))
|
2012-07-10 12:32:23 +00:00
|
|
|
self.out.nl()
|