Commit 4cd0a8b9 authored by calamity@chromium.org's avatar calamity@chromium.org

Fix map-branches issues and add coloring for 'branch-heads',

This CL fixes some issues with map-branches:
* Branches with no upstream were not being shown.
* -vv from a detached HEAD would crash
* GONE upstreams would crash when git cleaned up in a way that caused
  hash_one to fail

This CL also adds a blue coloring to branches that start with
'branch-heads' for Chromium release branches.

BUG=416530

Review URL: https://codereview.chromium.org/576423002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@292083 0039d316-1c4b-4281-b951-d872f2087c98
parent b5ccc9b1
...@@ -19,6 +19,7 @@ Branches are colorized as follows: ...@@ -19,6 +19,7 @@ Branches are colorized as follows:
* Note that multiple branches may be Cyan, if they are all on the same * Note that multiple branches may be Cyan, if they are all on the same
commit, and you have that commit checked out. commit, and you have that commit checked out.
* Green - a local branch * Green - a local branch
* Blue - a 'branch-heads' branch
* Magenta - a tag * Magenta - a tag
* Magenta '{NO UPSTREAM}' - If you have local branches which do not track any * Magenta '{NO UPSTREAM}' - If you have local branches which do not track any
upstream, then you will see this. upstream, then you will see this.
...@@ -27,6 +28,7 @@ Branches are colorized as follows: ...@@ -27,6 +28,7 @@ Branches are colorized as follows:
import argparse import argparse
import collections import collections
import sys import sys
import subprocess2
from third_party import colorama from third_party import colorama
from third_party.colorama import Fore, Style from third_party.colorama import Fore, Style
...@@ -126,7 +128,7 @@ class BranchMapper(object): ...@@ -126,7 +128,7 @@ class BranchMapper(object):
continue continue
parent = branch_info.upstream parent = branch_info.upstream
if parent and not self.__branches_info[parent]: if not self.__branches_info[parent]:
branch_upstream = upstream(branch) branch_upstream = upstream(branch)
# If git can't find the upstream, mark the upstream as gone. # If git can't find the upstream, mark the upstream as gone.
if branch_upstream: if branch_upstream:
...@@ -156,6 +158,8 @@ class BranchMapper(object): ...@@ -156,6 +158,8 @@ class BranchMapper(object):
def __color_for_branch(self, branch, branch_hash): def __color_for_branch(self, branch, branch_hash):
if branch.startswith('origin'): if branch.startswith('origin'):
color = Fore.RED color = Fore.RED
elif branch.startswith('branch-heads'):
color = Fore.BLUE
elif self.__is_invalid_parent(branch) or branch in self.__tag_set: elif self.__is_invalid_parent(branch) or branch in self.__tag_set:
color = Fore.MAGENTA color = Fore.MAGENTA
elif self.__current_hash.startswith(branch_hash): elif self.__current_hash.startswith(branch_hash):
...@@ -163,7 +167,7 @@ class BranchMapper(object): ...@@ -163,7 +167,7 @@ class BranchMapper(object):
else: else:
color = Fore.GREEN color = Fore.GREEN
if self.__current_hash.startswith(branch_hash): if branch_hash and self.__current_hash.startswith(branch_hash):
color += Style.BRIGHT color += Style.BRIGHT
else: else:
color += Style.NORMAL color += Style.NORMAL
...@@ -177,7 +181,10 @@ class BranchMapper(object): ...@@ -177,7 +181,10 @@ class BranchMapper(object):
if branch_info: if branch_info:
branch_hash = branch_info.hash branch_hash = branch_info.hash
else: else:
branch_hash = hash_one(branch, short=True) try:
branch_hash = hash_one(branch, short=True)
except subprocess2.CalledProcessError:
branch_hash = None
line = OutputLine() line = OutputLine()
...@@ -233,7 +240,8 @@ class BranchMapper(object): ...@@ -233,7 +240,8 @@ class BranchMapper(object):
if self.verbosity >= 2: if self.verbosity >= 2:
import git_cl # avoid heavy import cost unless we need it import git_cl # avoid heavy import cost unless we need it
none_text = '' if self.__is_invalid_parent(branch) else 'None' none_text = '' if self.__is_invalid_parent(branch) else 'None'
url = git_cl.Changelist(branchref=branch).GetIssueURL() url = git_cl.Changelist(
branchref=branch).GetIssueURL() if branch_hash else None
line.append(url or none_text, color=Fore.BLUE if url else Fore.WHITE) line.append(url or none_text, color=Fore.BLUE if url else Fore.WHITE)
self.output.append(line) self.output.append(line)
......
...@@ -790,6 +790,11 @@ Remote branches are <span class="red">red</span> (usually, the root of all other ...@@ -790,6 +790,11 @@ Remote branches are <span class="red">red</span> (usually, the root of all other
</li> </li>
<li> <li>
<p> <p>
<em>branch-heads</em> branches are <span class="blue">blue</span>.
</p>
</li>
<li>
<p>
<code>{NO UPSTREAM}</code> is a special placeholder in <span class="fuchsia">magenta</span>. <code>{NO UPSTREAM}</code> is a special placeholder in <span class="fuchsia">magenta</span>.
</p> </p>
<div class="ulist"><ul> <div class="ulist"><ul>
...@@ -820,13 +825,13 @@ Branches which have this as their parent are usually misconfigured, and ...@@ -820,13 +825,13 @@ Branches which have this as their parent are usually misconfigured, and
assuming that the <code>frozen_changes</code> branch was currently checked out, running assuming that the <code>frozen_changes</code> branch was currently checked out, running
<em>git map-branches</em> would result in an output like:</p></div> <em>git map-branches</em> would result in an output like:</p></div>
<div class="paragraph"><p></p></div><div class="listingblock"><div class="content"><pre><code><span style="font-weight: bold; color: #ffffff">$ git map-branches</span> <div class="paragraph"><p></p></div><div class="listingblock"><div class="content"><pre><code><span style="font-weight: bold; color: #ffffff">$ git map-branches</span>
<span style="color: #e42e16"></span><span style="color: #e42e16">origin/master <span style="color: #d338d3"></span><span style="color: #d338d3">{NO_UPSTREAM}
</span><span style="color: #19c518"></span><span style="color: #19c518"> no_upstream
</span><span style="color: #e42e16"></span><span style="color: #e42e16">origin/master
</span><span style="color: #19c518"></span><span style="color: #19c518"> cool_feature </span><span style="color: #19c518"></span><span style="color: #19c518"> cool_feature
</span><span style="color: #19c518"></span><span style="color: #19c518"> subfeature </span><span style="color: #19c518"></span><span style="color: #19c518"> subfeature
</span><span style="color: #19c518"></span><span style="color: #19c518"> fixit </span><span style="color: #19c518"></span><span style="color: #19c518"> fixit
</span><span style="color: #33d6e5"></span><span style="font-weight: bold; color: #33d6e5"> frozen_branch * </span><span style="color: #33d6e5"></span><span style="font-weight: bold; color: #33d6e5"> frozen_branch *</span>
</span><span style="font-weight: bold; color: #d338d3"></span><span style="color: #d338d3">{NO UPSTREAM}
</span><span style="color: #19c518"></span><span style="color: #19c518"> no_upstream</span>
</code></pre></div></div><p><div class="paragraph"></p></div> </code></pre></div></div><p><div class="paragraph"></p></div>
</div> </div>
</div> </div>
...@@ -860,7 +865,7 @@ from <a href="https://chromium.googlesource.com/chromium/tools/depot_tools.git"> ...@@ -860,7 +865,7 @@ from <a href="https://chromium.googlesource.com/chromium/tools/depot_tools.git">
<div id="footnotes"><hr /></div> <div id="footnotes"><hr /></div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Last updated 2014-04-10 14:23:11 PDT Last updated 2014-09-23 13:01:42 EST
</div> </div>
</div> </div>
</body> </body>
......
'\" t '\" t
.\" Title: git-map-branches .\" Title: git-map-branches
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/> .\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
.\" Date: 04/10/2014 .\" Date: 09/23/2014
.\" Manual: Chromium depot_tools Manual .\" Manual: Chromium depot_tools Manual
.\" Source: depot_tools 68b1017 .\" Source: depot_tools 28bf2be
.\" Language: English .\" Language: English
.\" .\"
.TH "GIT\-MAP\-BRANCHES" "1" "04/10/2014" "depot_tools 68b1017" "Chromium depot_tools Manual" .TH "GIT\-MAP\-BRANCHES" "1" "09/23/2014" "depot_tools 28bf2be" "Chromium depot_tools Manual"
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
.\" * Define some portability stuff .\" * Define some portability stuff
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
...@@ -95,6 +95,21 @@ red ...@@ -95,6 +95,21 @@ red
.sp -1 .sp -1
.IP \(bu 2.3 .IP \(bu 2.3
.\} .\}
\fIbranch\-heads\fR
branches are
blue\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
{NO UPSTREAM} {NO UPSTREAM}
is a special placeholder in is a special placeholder in
magenta\&. magenta\&.
...@@ -137,13 +152,13 @@ Given the hypothetical demo repo in \fBgit-map\fR(1)\*(Aqs EXAMPLE section, and ...@@ -137,13 +152,13 @@ Given the hypothetical demo repo in \fBgit-map\fR(1)\*(Aqs EXAMPLE section, and
.\} .\}
.nf .nf
\fB$ git map\-branches\fR \fB$ git map\-branches\fR
{NO_UPSTREAM}
no_upstream
origin/master origin/master
cool_feature cool_feature
subfeature subfeature
fixit fixit
\fB frozen_branch * \fB frozen_branch *\fR
\fR{NO UPSTREAM}
no_upstream
.fi .fi
.if n \{\ .if n \{\
.RE .RE
......
...@@ -21,6 +21,7 @@ Git map-branches displays all local branches such that: ...@@ -21,6 +21,7 @@ Git map-branches displays all local branches such that:
(`*`) after the name. (`*`) after the name.
* Local branches are [green]#green#. * Local branches are [green]#green#.
* Remote branches are [red]#red# (usually, the root of all other branches). * Remote branches are [red]#red# (usually, the root of all other branches).
* 'branch-heads' branches are [blue]#blue#.
* `{NO UPSTREAM}` is a special placeholder in [fuchsia]#magenta#. * `{NO UPSTREAM}` is a special placeholder in [fuchsia]#magenta#.
** Branches which have this as their parent are usually misconfigured, and ** Branches which have this as their parent are usually misconfigured, and
should be assigned a parent by checking out the branch and running git branch should be assigned a parent by checking out the branch and running git branch
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment