From 4cd0a8b9d6822c8f140da5ede38ad4428b991215 Mon Sep 17 00:00:00 2001 From: "calamity@chromium.org" Date: Tue, 23 Sep 2014 03:30:50 +0000 Subject: [PATCH] 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 --- git_map_branches.py | 16 ++++++++++++---- man/html/git-map-branches.html | 15 ++++++++++----- man/man1/git-map-branches.1 | 29 ++++++++++++++++++++++------- man/src/git-map-branches.txt | 1 + 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/git_map_branches.py b/git_map_branches.py index 350fed37a..44f13c3bd 100755 --- a/git_map_branches.py +++ b/git_map_branches.py @@ -19,6 +19,7 @@ Branches are colorized as follows: * Note that multiple branches may be Cyan, if they are all on the same commit, and you have that commit checked out. * Green - a local branch + * Blue - a 'branch-heads' branch * Magenta - a tag * Magenta '{NO UPSTREAM}' - If you have local branches which do not track any upstream, then you will see this. @@ -27,6 +28,7 @@ Branches are colorized as follows: import argparse import collections import sys +import subprocess2 from third_party import colorama from third_party.colorama import Fore, Style @@ -126,7 +128,7 @@ class BranchMapper(object): continue parent = branch_info.upstream - if parent and not self.__branches_info[parent]: + if not self.__branches_info[parent]: branch_upstream = upstream(branch) # If git can't find the upstream, mark the upstream as gone. if branch_upstream: @@ -156,6 +158,8 @@ class BranchMapper(object): def __color_for_branch(self, branch, branch_hash): if branch.startswith('origin'): color = Fore.RED + elif branch.startswith('branch-heads'): + color = Fore.BLUE elif self.__is_invalid_parent(branch) or branch in self.__tag_set: color = Fore.MAGENTA elif self.__current_hash.startswith(branch_hash): @@ -163,7 +167,7 @@ class BranchMapper(object): else: color = Fore.GREEN - if self.__current_hash.startswith(branch_hash): + if branch_hash and self.__current_hash.startswith(branch_hash): color += Style.BRIGHT else: color += Style.NORMAL @@ -177,7 +181,10 @@ class BranchMapper(object): if branch_info: branch_hash = branch_info.hash else: - branch_hash = hash_one(branch, short=True) + try: + branch_hash = hash_one(branch, short=True) + except subprocess2.CalledProcessError: + branch_hash = None line = OutputLine() @@ -233,7 +240,8 @@ class BranchMapper(object): if self.verbosity >= 2: import git_cl # avoid heavy import cost unless we need it 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) self.output.append(line) diff --git a/man/html/git-map-branches.html b/man/html/git-map-branches.html index e3d1d330f..5ac03db11 100644 --- a/man/html/git-map-branches.html +++ b/man/html/git-map-branches.html @@ -790,6 +790,11 @@ Remote branches are red (usually, the root of all other
  • +branch-heads branches are blue. +

    +
  • +
  • +

    {NO UPSTREAM} is a special placeholder in magenta.

      @@ -820,13 +825,13 @@ Branches which have this as their parent are usually misconfigured, and assuming that the frozen_changes branch was currently checked out, running git map-branches would result in an output like:

    $ git map-branches
    -origin/master
    +{NO_UPSTREAM}
    +  no_upstream
    +origin/master
       cool_feature
         subfeature
       fixit
    -    frozen_branch *
    -{NO UPSTREAM}
    -  no_upstream
    +    frozen_branch *
     

    @@ -860,7 +865,7 @@ from

    diff --git a/man/man1/git-map-branches.1 b/man/man1/git-map-branches.1 index 857825327..552a495ed 100644 --- a/man/man1/git-map-branches.1 +++ b/man/man1/git-map-branches.1 @@ -1,13 +1,13 @@ '\" t .\" Title: git-map-branches .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] -.\" Generator: DocBook XSL Stylesheets v1.78.1 -.\" Date: 04/10/2014 +.\" Generator: DocBook XSL Stylesheets v1.76.1 +.\" Date: 09/23/2014 .\" Manual: Chromium depot_tools Manual -.\" Source: depot_tools 68b1017 +.\" Source: depot_tools 28bf2be .\" 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 .\" ----------------------------------------------------------------- @@ -95,6 +95,21 @@ red .sp -1 .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} is a special placeholder in magenta\&. @@ -137,13 +152,13 @@ Given the hypothetical demo repo in \fBgit-map\fR(1)\*(Aqs EXAMPLE section, and .\} .nf \fB$ git map\-branches\fR +{NO_UPSTREAM} + no_upstream origin/master cool_feature subfeature fixit -\fB frozen_branch * -\fR{NO UPSTREAM} - no_upstream +\fB frozen_branch *\fR .fi .if n \{\ .RE diff --git a/man/src/git-map-branches.txt b/man/src/git-map-branches.txt index a925e9c56..1bae3fba1 100644 --- a/man/src/git-map-branches.txt +++ b/man/src/git-map-branches.txt @@ -21,6 +21,7 @@ Git map-branches displays all local branches such that: (`*`) after the name. * Local branches are [green]#green#. * 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#. ** 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