Mike Frysinger | f601376 | 2019-06-13 02:30:51 -0400 | [diff] [blame^] | 1 | # -*- coding:utf-8 -*- |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 2 | # |
| 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 | |
| 17 | from command import PagedCommand |
| 18 | from color import Coloring |
| 19 | from error import NoSuchProjectError |
| 20 | from git_refs import R_M |
| 21 | |
| 22 | class _Coloring(Coloring): |
| 23 | def __init__(self, config): |
| 24 | Coloring.__init__(self, config, "status") |
| 25 | |
| 26 | class 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 Pursehouse | da45e5d | 2013-05-15 17:34:45 +0900 | [diff] [blame] | 31 | def _Options(self, p): |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 32 | 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 Schuberth | 266f74c | 2019-04-17 19:08:52 +0200 | [diff] [blame] | 49 | self.headtext = self.out.nofmt_printer('headtext', fg = 'yellow') |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 50 | self.redtext = self.out.printer('redtext', fg = 'red') |
| 51 | self.sha = self.out.printer("sha", fg = 'yellow') |
Olof Johansson | 75b4c2d | 2013-02-18 13:18:16 +0100 | [diff] [blame] | 52 | self.text = self.out.nofmt_printer('text') |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 53 | self.dimtext = self.out.printer('dimtext', attr = 'dim') |
| 54 | |
| 55 | self.opt = opt |
| 56 | |
Conley Owens | 61ac9ae | 2013-03-05 10:35:36 -0800 | [diff] [blame] | 57 | manifestConfig = self.manifest.manifestProject.config |
| 58 | mergeBranch = manifestConfig.GetBranch("default").merge |
| 59 | manifestGroups = (manifestConfig.GetString('manifest.groups') |
| 60 | or 'all,-notdefault') |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 61 | |
| 62 | self.heading("Manifest branch: ") |
Cassidy Burden | 17af578 | 2015-06-29 14:51:35 -0700 | [diff] [blame] | 63 | if self.manifest.default.revisionExpr: |
| 64 | self.headtext(self.manifest.default.revisionExpr) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 65 | self.out.nl() |
| 66 | self.heading("Manifest merge branch: ") |
| 67 | self.headtext(mergeBranch) |
| 68 | self.out.nl() |
Conley Owens | 61ac9ae | 2013-03-05 10:35:36 -0800 | [diff] [blame] | 69 | self.heading("Manifest groups: ") |
| 70 | self.headtext(manifestGroups) |
| 71 | self.out.nl() |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 72 | |
| 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 Frysinger | 31067c0 | 2019-06-13 02:13:23 -0400 | [diff] [blame] | 103 | localBranches = list(p.GetBranches().keys()) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 104 | 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 Johansson | 57bd7b7 | 2013-01-29 08:22:05 +0100 | [diff] [blame] | 122 | logTarget = R_M + self.manifest.manifestProject.config.GetBranch("default").merge |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 123 | |
| 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 Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 149 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 150 | 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 Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 161 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 162 | 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 Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 168 | for x in project.GetBranches()] |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 169 | 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 Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 202 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 203 | self.out.nl() |