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 | |
| 30 | def _Options(self, p, show_smart=True): |
| 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: ") |
| 62 | self.headtext(self.manifest.default.revisionExpr) |
| 63 | self.out.nl() |
| 64 | self.heading("Manifest merge branch: ") |
| 65 | self.headtext(mergeBranch) |
| 66 | self.out.nl() |
Conley Owens | 61ac9ae | 2013-03-05 10:35:36 -0800 | [diff] [blame] | 67 | self.heading("Manifest groups: ") |
| 68 | self.headtext(manifestGroups) |
| 69 | self.out.nl() |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 70 | |
| 71 | self.printSeparator() |
| 72 | |
| 73 | if not opt.overview: |
| 74 | self.printDiffInfo(args) |
| 75 | else: |
| 76 | self.printCommitOverview(args) |
| 77 | |
| 78 | def printSeparator(self): |
| 79 | self.text("----------------------------") |
| 80 | self.out.nl() |
| 81 | |
| 82 | def printDiffInfo(self, args): |
| 83 | try: |
| 84 | projs = self.GetProjects(args) |
| 85 | except NoSuchProjectError: |
| 86 | return |
| 87 | |
| 88 | for p in projs: |
| 89 | self.heading("Project: ") |
| 90 | self.headtext(p.name) |
| 91 | self.out.nl() |
| 92 | |
| 93 | self.heading("Mount path: ") |
| 94 | self.headtext(p.worktree) |
| 95 | self.out.nl() |
| 96 | |
| 97 | self.heading("Current revision: ") |
| 98 | self.headtext(p.revisionExpr) |
| 99 | self.out.nl() |
| 100 | |
| 101 | localBranches = p.GetBranches().keys() |
| 102 | self.heading("Local Branches: ") |
| 103 | self.redtext(str(len(localBranches))) |
| 104 | if len(localBranches) > 0: |
| 105 | self.text(" [") |
| 106 | self.text(", ".join(localBranches)) |
| 107 | self.text("]") |
| 108 | self.out.nl() |
| 109 | |
| 110 | if self.opt.all: |
| 111 | self.findRemoteLocalDiff(p) |
| 112 | |
| 113 | self.printSeparator() |
| 114 | |
| 115 | def findRemoteLocalDiff(self, project): |
| 116 | #Fetch all the latest commits |
| 117 | if not self.opt.local: |
| 118 | project.Sync_NetworkHalf(quiet=True, current_branch_only=True) |
| 119 | |
Olof Johansson | 57bd7b7 | 2013-01-29 08:22:05 +0100 | [diff] [blame] | 120 | logTarget = R_M + self.manifest.manifestProject.config.GetBranch("default").merge |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 121 | |
| 122 | bareTmp = project.bare_git._bare |
| 123 | project.bare_git._bare = False |
| 124 | localCommits = project.bare_git.rev_list( |
| 125 | '--abbrev=8', |
| 126 | '--abbrev-commit', |
| 127 | '--pretty=oneline', |
| 128 | logTarget + "..", |
| 129 | '--') |
| 130 | |
| 131 | originCommits = project.bare_git.rev_list( |
| 132 | '--abbrev=8', |
| 133 | '--abbrev-commit', |
| 134 | '--pretty=oneline', |
| 135 | ".." + logTarget, |
| 136 | '--') |
| 137 | project.bare_git._bare = bareTmp |
| 138 | |
| 139 | self.heading("Local Commits: ") |
| 140 | self.redtext(str(len(localCommits))) |
| 141 | self.dimtext(" (on current branch)") |
| 142 | self.out.nl() |
| 143 | |
| 144 | for c in localCommits: |
| 145 | split = c.split() |
| 146 | self.sha(split[0] + " ") |
David Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 147 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 148 | self.out.nl() |
| 149 | |
| 150 | self.printSeparator() |
| 151 | |
| 152 | self.heading("Remote Commits: ") |
| 153 | self.redtext(str(len(originCommits))) |
| 154 | self.out.nl() |
| 155 | |
| 156 | for c in originCommits: |
| 157 | split = c.split() |
| 158 | self.sha(split[0] + " ") |
David Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 159 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 160 | self.out.nl() |
| 161 | |
| 162 | def printCommitOverview(self, args): |
| 163 | all_branches = [] |
| 164 | for project in self.GetProjects(args): |
| 165 | br = [project.GetUploadableBranch(x) |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 166 | for x in project.GetBranches()] |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 167 | br = [x for x in br if x] |
| 168 | if self.opt.current_branch: |
| 169 | br = [x for x in br if x.name == project.CurrentBranch] |
| 170 | all_branches.extend(br) |
| 171 | |
| 172 | if not all_branches: |
| 173 | return |
| 174 | |
| 175 | self.out.nl() |
| 176 | self.heading('Projects Overview') |
| 177 | project = None |
| 178 | |
| 179 | for branch in all_branches: |
| 180 | if project != branch.project: |
| 181 | project = branch.project |
| 182 | self.out.nl() |
| 183 | self.headtext(project.relpath) |
| 184 | self.out.nl() |
| 185 | |
| 186 | commits = branch.commits |
| 187 | date = branch.date |
| 188 | self.text('%s %-33s (%2d commit%s, %s)' % ( |
| 189 | branch.name == project.CurrentBranch and '*' or ' ', |
| 190 | branch.name, |
| 191 | len(commits), |
| 192 | len(commits) != 1 and 's' or '', |
| 193 | date)) |
| 194 | self.out.nl() |
| 195 | |
| 196 | for commit in commits: |
| 197 | split = commit.split() |
| 198 | self.text('{0:38}{1} '.format('','-')) |
| 199 | self.sha(split[0] + " ") |
David Pursehouse | e0b6de3 | 2012-11-21 17:36:28 +0900 | [diff] [blame] | 200 | self.text(" ".join(split[1:])) |
Olof Johansson | 33949c3 | 2012-07-10 14:32:23 +0200 | [diff] [blame] | 201 | self.out.nl() |