Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2012 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | from command import PagedCommand |
| 17 | from color import Coloring |
| 18 | from error import NoSuchProjectError |
| 19 | from git_refs import R_M |
| 20 | |
| 21 | class _Coloring(Coloring): |
| 22 | def __init__(self, config): |
| 23 | Coloring.__init__(self, config, "status") |
| 24 | |
| 25 | class 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 Pursehouse | da45e5d | 2013-05-15 17:34:45 +0900 | [diff] [blame] | 30 | def _Options(self, p): |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 31 | 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') |
| 48 | self.headtext = self.out.printer('headtext', fg = 'yellow') |
| 49 | self.redtext = self.out.printer('redtext', fg = 'red') |
| 50 | self.sha = self.out.printer("sha", fg = 'yellow') |
Olof Johansson | 75b4c2d | 2013-02-18 13:18:16 +0100 | [diff] [blame] | 51 | self.text = self.out.nofmt_printer('text') |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 52 | self.dimtext = self.out.printer('dimtext', attr = 'dim') |
| 53 | |
| 54 | self.opt = opt |
| 55 | |
Conley Owens | 61ac9ae | 2013-03-05 10:35:36 -0800 | [diff] [blame] | 56 | manifestConfig = self.manifest.manifestProject.config |
| 57 | mergeBranch = manifestConfig.GetBranch("default").merge |
| 58 | manifestGroups = (manifestConfig.GetString('manifest.groups') |
| 59 | or 'all,-notdefault') |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 60 | |
| 61 | self.heading("Manifest branch: ") |
Cassidy Burden | 17af578 | 2015-06-29 14:51:35 -0700 | [diff] [blame] | 62 | if self.manifest.default.revisionExpr: |
| 63 | self.headtext(self.manifest.default.revisionExpr) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 64 | self.out.nl() |
| 65 | self.heading("Manifest merge branch: ") |
| 66 | self.headtext(mergeBranch) |
| 67 | self.out.nl() |
Conley Owens | 61ac9ae | 2013-03-05 10:35:36 -0800 | [diff] [blame] | 68 | self.heading("Manifest groups: ") |
| 69 | self.headtext(manifestGroups) |
| 70 | self.out.nl() |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 71 | |
| 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): |
| 84 | try: |
| 85 | projs = self.GetProjects(args) |
| 86 | except NoSuchProjectError: |
| 87 | return |
| 88 | |
| 89 | for p in projs: |
| 90 | self.heading("Project: ") |
| 91 | self.headtext(p.name) |
| 92 | self.out.nl() |
| 93 | |
| 94 | self.heading("Mount path: ") |
| 95 | self.headtext(p.worktree) |
| 96 | self.out.nl() |
| 97 | |
| 98 | self.heading("Current revision: ") |
| 99 | self.headtext(p.revisionExpr) |
| 100 | self.out.nl() |
| 101 | |
| 102 | localBranches = p.GetBranches().keys() |
| 103 | self.heading("Local Branches: ") |
| 104 | self.redtext(str(len(localBranches))) |
| 105 | if len(localBranches) > 0: |
| 106 | self.text(" [") |
| 107 | self.text(", ".join(localBranches)) |
| 108 | self.text("]") |
| 109 | self.out.nl() |
| 110 | |
| 111 | if self.opt.all: |
| 112 | self.findRemoteLocalDiff(p) |
| 113 | |
| 114 | self.printSeparator() |
| 115 | |
| 116 | def findRemoteLocalDiff(self, project): |
| 117 | #Fetch all the latest commits |
| 118 | if not self.opt.local: |
| 119 | project.Sync_NetworkHalf(quiet=True, current_branch_only=True) |
| 120 | |
Olof Johansson | 57bd7b7 | 2013-01-29 08:22:05 +0100 | [diff] [blame] | 121 | logTarget = R_M + self.manifest.manifestProject.config.GetBranch("default").merge |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 122 | |
| 123 | bareTmp = project.bare_git._bare |
| 124 | project.bare_git._bare = False |
| 125 | localCommits = project.bare_git.rev_list( |
| 126 | '--abbrev=8', |
| 127 | '--abbrev-commit', |
| 128 | '--pretty=oneline', |
| 129 | logTarget + "..", |
| 130 | '--') |
| 131 | |
| 132 | originCommits = project.bare_git.rev_list( |
| 133 | '--abbrev=8', |
| 134 | '--abbrev-commit', |
| 135 | '--pretty=oneline', |
| 136 | ".." + logTarget, |
| 137 | '--') |
| 138 | project.bare_git._bare = bareTmp |
| 139 | |
| 140 | self.heading("Local Commits: ") |
| 141 | self.redtext(str(len(localCommits))) |
| 142 | self.dimtext(" (on current branch)") |
| 143 | self.out.nl() |
| 144 | |
| 145 | for c in localCommits: |
| 146 | split = c.split() |
| 147 | self.sha(split[0] + " ") |
David Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 148 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 149 | self.out.nl() |
| 150 | |
| 151 | self.printSeparator() |
| 152 | |
| 153 | self.heading("Remote Commits: ") |
| 154 | self.redtext(str(len(originCommits))) |
| 155 | self.out.nl() |
| 156 | |
| 157 | for c in originCommits: |
| 158 | split = c.split() |
| 159 | self.sha(split[0] + " ") |
David Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 160 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 161 | self.out.nl() |
| 162 | |
| 163 | def printCommitOverview(self, args): |
| 164 | all_branches = [] |
| 165 | for project in self.GetProjects(args): |
| 166 | br = [project.GetUploadableBranch(x) |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 167 | for x in project.GetBranches()] |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 168 | br = [x for x in br if x] |
| 169 | if self.opt.current_branch: |
| 170 | br = [x for x in br if x.name == project.CurrentBranch] |
| 171 | all_branches.extend(br) |
| 172 | |
| 173 | if not all_branches: |
| 174 | return |
| 175 | |
| 176 | self.out.nl() |
| 177 | self.heading('Projects Overview') |
| 178 | project = None |
| 179 | |
| 180 | for branch in all_branches: |
| 181 | if project != branch.project: |
| 182 | project = branch.project |
| 183 | self.out.nl() |
| 184 | self.headtext(project.relpath) |
| 185 | self.out.nl() |
| 186 | |
| 187 | commits = branch.commits |
| 188 | date = branch.date |
| 189 | self.text('%s %-33s (%2d commit%s, %s)' % ( |
| 190 | branch.name == project.CurrentBranch and '*' or ' ', |
| 191 | branch.name, |
| 192 | len(commits), |
| 193 | len(commits) != 1 and 's' or '', |
| 194 | date)) |
| 195 | self.out.nl() |
| 196 | |
| 197 | for commit in commits: |
| 198 | split = commit.split() |
| 199 | self.text('{0:38}{1} '.format('','-')) |
| 200 | self.sha(split[0] + " ") |
David Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 201 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 202 | self.out.nl() |