Edward Lemur | d6186f9 | 2019-08-12 17:56:58 +0000 | [diff] [blame] | 1 | #!/usr/bin/env vpython |
iannucci@chromium.org | a112f03 | 2014-03-13 07:47:50 +0000 | [diff] [blame] | 2 | # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
anatoly techtonik | 222840f | 2017-04-15 16:25:57 +0300 | [diff] [blame] | 6 | """Print dependency tree of branches in local repo. |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 7 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 8 | Example: |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 9 | origin/master |
| 10 | cool_feature |
| 11 | dependent_feature |
| 12 | other_dependent_feature |
| 13 | other_feature |
| 14 | |
| 15 | Branches are colorized as follows: |
| 16 | * Red - a remote branch (usually the root of all local branches) |
| 17 | * Cyan - a local branch which is the same as HEAD |
| 18 | * Note that multiple branches may be Cyan, if they are all on the same |
| 19 | commit, and you have that commit checked out. |
| 20 | * Green - a local branch |
calamity@chromium.org | 4cd0a8b | 2014-09-23 03:30:50 +0000 | [diff] [blame] | 21 | * Blue - a 'branch-heads' branch |
iannucci@chromium.org | c050a5b | 2014-03-26 06:18:50 +0000 | [diff] [blame] | 22 | * Magenta - a tag |
| 23 | * Magenta '{NO UPSTREAM}' - If you have local branches which do not track any |
| 24 | upstream, then you will see this. |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 25 | """ |
iannucci@chromium.org | c050a5b | 2014-03-26 06:18:50 +0000 | [diff] [blame] | 26 | |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 27 | from __future__ import print_function |
| 28 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 29 | import argparse |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 30 | import collections |
iannucci@chromium.org | 0703ea2 | 2016-04-01 01:02:42 +0000 | [diff] [blame] | 31 | import os |
calamity@chromium.org | 4cd0a8b | 2014-09-23 03:30:50 +0000 | [diff] [blame] | 32 | import subprocess2 |
iannucci@chromium.org | 596cd5c | 2016-04-04 21:34:39 +0000 | [diff] [blame] | 33 | import sys |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 34 | |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 35 | from git_common import current_branch, upstream, tags, get_branches_info |
iannucci@chromium.org | 4c82eb5 | 2014-09-08 02:12:24 +0000 | [diff] [blame] | 36 | from git_common import get_git_version, MIN_UPSTREAM_TRACK_GIT_VERSION, hash_one |
borenet@google.com | 09156ec | 2015-03-26 14:10:06 +0000 | [diff] [blame] | 37 | from git_common import run |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 38 | |
iannucci@chromium.org | 596cd5c | 2016-04-04 21:34:39 +0000 | [diff] [blame] | 39 | import setup_color |
| 40 | |
| 41 | from third_party.colorama import Fore, Style |
| 42 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 43 | DEFAULT_SEPARATOR = ' ' * 4 |
iannucci@chromium.org | c050a5b | 2014-03-26 06:18:50 +0000 | [diff] [blame] | 44 | |
| 45 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 46 | class OutputManager(object): |
| 47 | """Manages a number of OutputLines and formats them into aligned columns.""" |
iannucci@chromium.org | c050a5b | 2014-03-26 06:18:50 +0000 | [diff] [blame] | 48 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 49 | def __init__(self): |
| 50 | self.lines = [] |
| 51 | self.nocolor = False |
| 52 | self.max_column_lengths = [] |
| 53 | self.num_columns = None |
iannucci@chromium.org | c050a5b | 2014-03-26 06:18:50 +0000 | [diff] [blame] | 54 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 55 | def append(self, line): |
| 56 | # All lines must have the same number of columns. |
| 57 | if not self.num_columns: |
| 58 | self.num_columns = len(line.columns) |
| 59 | self.max_column_lengths = [0] * self.num_columns |
| 60 | assert self.num_columns == len(line.columns) |
| 61 | |
| 62 | if self.nocolor: |
| 63 | line.colors = [''] * self.num_columns |
| 64 | |
| 65 | self.lines.append(line) |
| 66 | |
| 67 | # Update maximum column lengths. |
| 68 | for i, col in enumerate(line.columns): |
| 69 | self.max_column_lengths[i] = max(self.max_column_lengths[i], len(col)) |
| 70 | |
| 71 | def as_formatted_string(self): |
| 72 | return '\n'.join( |
| 73 | l.as_padded_string(self.max_column_lengths) for l in self.lines) |
| 74 | |
| 75 | |
| 76 | class OutputLine(object): |
| 77 | """A single line of data. |
| 78 | |
| 79 | This consists of an equal number of columns, colors and separators.""" |
| 80 | |
| 81 | def __init__(self): |
| 82 | self.columns = [] |
| 83 | self.separators = [] |
| 84 | self.colors = [] |
| 85 | |
| 86 | def append(self, data, separator=DEFAULT_SEPARATOR, color=Fore.WHITE): |
| 87 | self.columns.append(data) |
| 88 | self.separators.append(separator) |
| 89 | self.colors.append(color) |
| 90 | |
| 91 | def as_padded_string(self, max_column_lengths): |
| 92 | """"Returns the data as a string with each column padded to |
| 93 | |max_column_lengths|.""" |
| 94 | output_string = '' |
| 95 | for i, (color, data, separator) in enumerate( |
| 96 | zip(self.colors, self.columns, self.separators)): |
| 97 | if max_column_lengths[i] == 0: |
| 98 | continue |
| 99 | |
| 100 | padding = (max_column_lengths[i] - len(data)) * ' ' |
| 101 | output_string += color + data + padding + separator |
| 102 | |
| 103 | return output_string.rstrip() |
| 104 | |
| 105 | |
| 106 | class BranchMapper(object): |
| 107 | """A class which constructs output representing the tree's branch structure. |
| 108 | |
| 109 | Attributes: |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 110 | __branches_info: a map of branches to their BranchesInfo objects which |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 111 | consist of the branch hash, upstream and ahead/behind status. |
| 112 | __gone_branches: a set of upstreams which are not fetchable by git""" |
| 113 | |
| 114 | def __init__(self): |
| 115 | self.verbosity = 0 |
calamity@chromium.org | ffde55c | 2015-03-12 00:44:17 +0000 | [diff] [blame] | 116 | self.maxjobs = 0 |
borenet@google.com | 09156ec | 2015-03-26 14:10:06 +0000 | [diff] [blame] | 117 | self.show_subject = False |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 118 | self.output = OutputManager() |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 119 | self.__gone_branches = set() |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 120 | self.__branches_info = None |
| 121 | self.__parent_map = collections.defaultdict(list) |
| 122 | self.__current_branch = None |
| 123 | self.__current_hash = None |
| 124 | self.__tag_set = None |
calamity@chromium.org | ffde55c | 2015-03-12 00:44:17 +0000 | [diff] [blame] | 125 | self.__status_info = {} |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 126 | |
| 127 | def start(self): |
| 128 | self.__branches_info = get_branches_info( |
| 129 | include_tracking_status=self.verbosity >= 1) |
calamity@chromium.org | ffde55c | 2015-03-12 00:44:17 +0000 | [diff] [blame] | 130 | if (self.verbosity >= 2): |
| 131 | # Avoid heavy import unless necessary. |
clemensh@chromium.org | cbd7dc3 | 2016-05-31 10:33:50 +0000 | [diff] [blame] | 132 | from git_cl import get_cl_statuses, color_for_status, Changelist |
calamity@chromium.org | ffde55c | 2015-03-12 00:44:17 +0000 | [diff] [blame] | 133 | |
clemensh@chromium.org | cbd7dc3 | 2016-05-31 10:33:50 +0000 | [diff] [blame] | 134 | change_cls = [Changelist(branchref='refs/heads/'+b) |
| 135 | for b in self.__branches_info.keys() if b] |
| 136 | status_info = get_cl_statuses(change_cls, |
calamity@chromium.org | ffde55c | 2015-03-12 00:44:17 +0000 | [diff] [blame] | 137 | fine_grained=self.verbosity > 2, |
| 138 | max_processes=self.maxjobs) |
| 139 | |
clemensh@chromium.org | cbd7dc3 | 2016-05-31 10:33:50 +0000 | [diff] [blame] | 140 | # This is a blocking get which waits for the remote CL status to be |
| 141 | # retrieved. |
| 142 | for cl, status in status_info: |
| 143 | self.__status_info[cl.GetBranch()] = (cl.GetIssueURL(), |
asanka | 97f3949 | 2016-07-18 18:16:40 -0700 | [diff] [blame] | 144 | color_for_status(status), |
| 145 | status) |
calamity@chromium.org | ffde55c | 2015-03-12 00:44:17 +0000 | [diff] [blame] | 146 | |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 147 | roots = set() |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 148 | |
| 149 | # A map of parents to a list of their children. |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 150 | for branch, branch_info in self.__branches_info.iteritems(): |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 151 | if not branch_info: |
| 152 | continue |
| 153 | |
| 154 | parent = branch_info.upstream |
Clemens Hammacher | 793183d | 2019-03-22 01:12:46 +0000 | [diff] [blame] | 155 | if self.__check_cycle(branch): |
| 156 | continue |
calamity@chromium.org | 4cd0a8b | 2014-09-23 03:30:50 +0000 | [diff] [blame] | 157 | if not self.__branches_info[parent]: |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 158 | branch_upstream = upstream(branch) |
| 159 | # If git can't find the upstream, mark the upstream as gone. |
| 160 | if branch_upstream: |
| 161 | parent = branch_upstream |
| 162 | else: |
| 163 | self.__gone_branches.add(parent) |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 164 | # A parent that isn't in the branches info is a root. |
| 165 | roots.add(parent) |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 166 | |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 167 | self.__parent_map[parent].append(branch) |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 168 | |
| 169 | self.__current_branch = current_branch() |
iannucci@chromium.org | 4c82eb5 | 2014-09-08 02:12:24 +0000 | [diff] [blame] | 170 | self.__current_hash = hash_one('HEAD', short=True) |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 171 | self.__tag_set = tags() |
| 172 | |
iannucci@chromium.org | 4c82eb5 | 2014-09-08 02:12:24 +0000 | [diff] [blame] | 173 | if roots: |
| 174 | for root in sorted(roots): |
| 175 | self.__append_branch(root) |
| 176 | else: |
| 177 | no_branches = OutputLine() |
| 178 | no_branches.append('No User Branches') |
| 179 | self.output.append(no_branches) |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 180 | |
Clemens Hammacher | 793183d | 2019-03-22 01:12:46 +0000 | [diff] [blame] | 181 | def __check_cycle(self, branch): |
| 182 | # Maximum length of the cycle is `num_branches`. This limit avoids running |
| 183 | # into a cycle which does *not* contain `branch`. |
| 184 | num_branches = len(self.__branches_info) |
| 185 | cycle = [branch] |
| 186 | while len(cycle) < num_branches and self.__branches_info[cycle[-1]]: |
| 187 | parent = self.__branches_info[cycle[-1]].upstream |
| 188 | cycle.append(parent) |
| 189 | if parent == branch: |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 190 | print('Warning: Detected cycle in branches: {}'.format( |
| 191 | ' -> '.join(cycle)), file=sys.stderr) |
Clemens Hammacher | 793183d | 2019-03-22 01:12:46 +0000 | [diff] [blame] | 192 | return True |
| 193 | return False |
| 194 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 195 | def __is_invalid_parent(self, parent): |
| 196 | return not parent or parent in self.__gone_branches |
| 197 | |
| 198 | def __color_for_branch(self, branch, branch_hash): |
jsbell@google.com | 4f1fc35 | 2016-03-24 22:23:46 +0000 | [diff] [blame] | 199 | if branch.startswith('origin/'): |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 200 | color = Fore.RED |
calamity@chromium.org | 4cd0a8b | 2014-09-23 03:30:50 +0000 | [diff] [blame] | 201 | elif branch.startswith('branch-heads'): |
| 202 | color = Fore.BLUE |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 203 | elif self.__is_invalid_parent(branch) or branch in self.__tag_set: |
| 204 | color = Fore.MAGENTA |
iannucci@chromium.org | 4c82eb5 | 2014-09-08 02:12:24 +0000 | [diff] [blame] | 205 | elif self.__current_hash.startswith(branch_hash): |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 206 | color = Fore.CYAN |
| 207 | else: |
| 208 | color = Fore.GREEN |
| 209 | |
calamity@chromium.org | 4cd0a8b | 2014-09-23 03:30:50 +0000 | [diff] [blame] | 210 | if branch_hash and self.__current_hash.startswith(branch_hash): |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 211 | color += Style.BRIGHT |
| 212 | else: |
| 213 | color += Style.NORMAL |
| 214 | |
| 215 | return color |
| 216 | |
| 217 | def __append_branch(self, branch, depth=0): |
| 218 | """Recurses through the tree structure and appends an OutputLine to the |
| 219 | OutputManager for each branch.""" |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 220 | branch_info = self.__branches_info[branch] |
iannucci@chromium.org | 4c82eb5 | 2014-09-08 02:12:24 +0000 | [diff] [blame] | 221 | if branch_info: |
| 222 | branch_hash = branch_info.hash |
| 223 | else: |
calamity@chromium.org | 4cd0a8b | 2014-09-23 03:30:50 +0000 | [diff] [blame] | 224 | try: |
| 225 | branch_hash = hash_one(branch, short=True) |
| 226 | except subprocess2.CalledProcessError: |
| 227 | branch_hash = None |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 228 | |
| 229 | line = OutputLine() |
| 230 | |
| 231 | # The branch name with appropriate indentation. |
| 232 | suffix = '' |
| 233 | if branch == self.__current_branch or ( |
| 234 | self.__current_branch == 'HEAD' and branch == self.__current_hash): |
iannucci@chromium.org | a112f03 | 2014-03-13 07:47:50 +0000 | [diff] [blame] | 235 | suffix = ' *' |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 236 | branch_string = branch |
| 237 | if branch in self.__gone_branches: |
| 238 | branch_string = '{%s:GONE}' % branch |
| 239 | if not branch: |
| 240 | branch_string = '{NO_UPSTREAM}' |
| 241 | main_string = ' ' * depth + branch_string + suffix |
| 242 | line.append( |
| 243 | main_string, |
| 244 | color=self.__color_for_branch(branch, branch_hash)) |
iannucci@chromium.org | a112f03 | 2014-03-13 07:47:50 +0000 | [diff] [blame] | 245 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 246 | # The branch hash. |
| 247 | if self.verbosity >= 2: |
| 248 | line.append(branch_hash or '', separator=' ', color=Fore.RED) |
| 249 | |
| 250 | # The branch tracking status. |
| 251 | if self.verbosity >= 1: |
| 252 | ahead_string = '' |
| 253 | behind_string = '' |
| 254 | front_separator = '' |
| 255 | center_separator = '' |
| 256 | back_separator = '' |
| 257 | if branch_info and not self.__is_invalid_parent(branch_info.upstream): |
| 258 | ahead = branch_info.ahead |
| 259 | behind = branch_info.behind |
| 260 | |
| 261 | if ahead: |
| 262 | ahead_string = 'ahead %d' % ahead |
| 263 | if behind: |
| 264 | behind_string = 'behind %d' % behind |
| 265 | |
| 266 | if ahead or behind: |
| 267 | front_separator = '[' |
| 268 | back_separator = ']' |
| 269 | |
| 270 | if ahead and behind: |
| 271 | center_separator = '|' |
| 272 | |
| 273 | line.append(front_separator, separator=' ') |
| 274 | line.append(ahead_string, separator=' ', color=Fore.MAGENTA) |
| 275 | line.append(center_separator, separator=' ') |
| 276 | line.append(behind_string, separator=' ', color=Fore.MAGENTA) |
| 277 | line.append(back_separator) |
| 278 | |
| 279 | # The Rietveld issue associated with the branch. |
| 280 | if self.verbosity >= 2: |
asanka | 97f3949 | 2016-07-18 18:16:40 -0700 | [diff] [blame] | 281 | (url, color, status) = ('', '', '') if self.__is_invalid_parent(branch) \ |
| 282 | else self.__status_info[branch] |
| 283 | if self.verbosity > 2: |
| 284 | line.append('{} ({})'.format(url, status) if url else '', color=color) |
| 285 | else: |
| 286 | line.append(url or '', color=color) |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 287 | |
borenet@google.com | 09156ec | 2015-03-26 14:10:06 +0000 | [diff] [blame] | 288 | # The subject of the most recent commit on the branch. |
| 289 | if self.show_subject: |
Aaron Gable | 6761b9d | 2017-08-28 12:23:40 -0700 | [diff] [blame] | 290 | if branch: |
| 291 | line.append(run('log', '-n1', '--format=%s', branch, '--')) |
| 292 | else: |
| 293 | line.append('') |
borenet@google.com | 09156ec | 2015-03-26 14:10:06 +0000 | [diff] [blame] | 294 | |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 295 | self.output.append(line) |
| 296 | |
calamity@chromium.org | 745ffa6 | 2014-09-08 01:03:19 +0000 | [diff] [blame] | 297 | for child in sorted(self.__parent_map.pop(branch, ())): |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 298 | self.__append_branch(child, depth=depth + 1) |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 299 | |
| 300 | |
anatoly techtonik | 222840f | 2017-04-15 16:25:57 +0300 | [diff] [blame] | 301 | def print_desc(): |
| 302 | for line in __doc__.splitlines(): |
| 303 | starpos = line.find('* ') |
| 304 | if starpos == -1 or '-' not in line: |
| 305 | print(line) |
| 306 | else: |
| 307 | _, color, rest = line.split(None, 2) |
| 308 | outline = line[:starpos+1] |
| 309 | outline += getattr(Fore, color.upper()) + " " + color + " " + Fore.RESET |
| 310 | outline += rest |
| 311 | print(outline) |
| 312 | print('') |
| 313 | |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 314 | def main(argv): |
iannucci@chromium.org | 596cd5c | 2016-04-04 21:34:39 +0000 | [diff] [blame] | 315 | setup_color.init() |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 316 | if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION: |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 317 | print( |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 318 | 'This tool will not show all tracking information for git version ' |
| 319 | 'earlier than ' + |
| 320 | '.'.join(str(x) for x in MIN_UPSTREAM_TRACK_GIT_VERSION) + |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 321 | '. Please consider upgrading.', file=sys.stderr) |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 322 | |
anatoly techtonik | 222840f | 2017-04-15 16:25:57 +0300 | [diff] [blame] | 323 | if '-h' in argv: |
| 324 | print_desc() |
| 325 | |
| 326 | parser = argparse.ArgumentParser() |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 327 | parser.add_argument('-v', action='count', |
Clemens Hammacher | 03640c7 | 2018-12-13 08:08:19 +0000 | [diff] [blame] | 328 | help=('Pass once to show tracking info, ' |
| 329 | 'twice for hash and review url, ' |
| 330 | 'thrice for review status')) |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 331 | parser.add_argument('--no-color', action='store_true', dest='nocolor', |
| 332 | help='Turn off colors.') |
calamity@chromium.org | ffde55c | 2015-03-12 00:44:17 +0000 | [diff] [blame] | 333 | parser.add_argument( |
| 334 | '-j', '--maxjobs', action='store', type=int, |
| 335 | help='The number of jobs to use when retrieving review status') |
borenet@google.com | 09156ec | 2015-03-26 14:10:06 +0000 | [diff] [blame] | 336 | parser.add_argument('--show-subject', action='store_true', |
| 337 | dest='show_subject', help='Show the commit subject.') |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 338 | |
sbc@chromium.org | 013731e | 2015-02-26 18:28:43 +0000 | [diff] [blame] | 339 | opts = parser.parse_args(argv) |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 340 | |
| 341 | mapper = BranchMapper() |
| 342 | mapper.verbosity = opts.v |
| 343 | mapper.output.nocolor = opts.nocolor |
calamity@chromium.org | ffde55c | 2015-03-12 00:44:17 +0000 | [diff] [blame] | 344 | mapper.maxjobs = opts.maxjobs |
borenet@google.com | 09156ec | 2015-03-26 14:10:06 +0000 | [diff] [blame] | 345 | mapper.show_subject = opts.show_subject |
calamity@chromium.org | 9d2c880 | 2014-09-03 02:04:46 +0000 | [diff] [blame] | 346 | mapper.start() |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 347 | print(mapper.output.as_formatted_string()) |
sbc@chromium.org | 013731e | 2015-02-26 18:28:43 +0000 | [diff] [blame] | 348 | return 0 |
iannucci@chromium.org | 8bc9b5c | 2014-03-12 01:36:18 +0000 | [diff] [blame] | 349 | |
| 350 | if __name__ == '__main__': |
sbc@chromium.org | 013731e | 2015-02-26 18:28:43 +0000 | [diff] [blame] | 351 | try: |
| 352 | sys.exit(main(sys.argv[1:])) |
| 353 | except KeyboardInterrupt: |
| 354 | sys.stderr.write('interrupted\n') |
| 355 | sys.exit(1) |