Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Provides a short mapping of all the branches in your local repo, organized | 6 """Provides a short mapping of all the branches in your local repo, organized |
| 7 by their upstream ('tracking branch') layout. | 7 by their upstream ('tracking branch') layout. |
| 8 | 8 |
| 9 Example: | 9 Example: |
| 10 origin/master | 10 origin/master |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 | 109 |
| 110 def __init__(self): | 110 def __init__(self): |
| 111 self.verbosity = 0 | 111 self.verbosity = 0 |
| 112 self.output = OutputManager() | 112 self.output = OutputManager() |
| 113 self.__gone_branches = set() | 113 self.__gone_branches = set() |
| 114 self.__branches_info = None | 114 self.__branches_info = None |
| 115 self.__parent_map = collections.defaultdict(list) | 115 self.__parent_map = collections.defaultdict(list) |
| 116 self.__current_branch = None | 116 self.__current_branch = None |
| 117 self.__current_hash = None | 117 self.__current_hash = None |
| 118 self.__tag_set = None | 118 self.__tag_set = None |
| 119 self.__status_info = None | |
| 119 | 120 |
| 120 def start(self): | 121 def start(self): |
| 121 self.__branches_info = get_branches_info( | 122 self.__branches_info = get_branches_info( |
| 122 include_tracking_status=self.verbosity >= 1) | 123 include_tracking_status=self.verbosity >= 1) |
| 124 if (self.verbosity >= 2): | |
| 125 # Avoid heavy import unless necessary. | |
| 126 from git_cl import get_cl_statuses | |
| 127 | |
| 128 self.__status_info = {} | |
| 129 status_info = get_cl_statuses(self.__branches_info.keys(), | |
| 130 self.verbosity == 2) | |
| 131 | |
| 132 threads_left = len(self.__branches_info) | |
|
jsbell
2015/02/27 17:39:38
Maybe `queue_length` or `branch_count` instead of
calamity
2015/03/02 02:35:03
Done.
| |
| 133 for i in xrange(threads_left): | |
| 134 (branch, url, color) = status_info.get() | |
| 135 self.__status_info[branch] = (url, color); | |
| 136 | |
| 123 roots = set() | 137 roots = set() |
| 124 | 138 |
| 125 # A map of parents to a list of their children. | 139 # A map of parents to a list of their children. |
| 126 for branch, branch_info in self.__branches_info.iteritems(): | 140 for branch, branch_info in self.__branches_info.iteritems(): |
| 127 if not branch_info: | 141 if not branch_info: |
| 128 continue | 142 continue |
| 129 | 143 |
| 130 parent = branch_info.upstream | 144 parent = branch_info.upstream |
| 131 if not self.__branches_info[parent]: | 145 if not self.__branches_info[parent]: |
| 132 branch_upstream = upstream(branch) | 146 branch_upstream = upstream(branch) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 if ahead and behind: | 244 if ahead and behind: |
| 231 center_separator = '|' | 245 center_separator = '|' |
| 232 | 246 |
| 233 line.append(front_separator, separator=' ') | 247 line.append(front_separator, separator=' ') |
| 234 line.append(ahead_string, separator=' ', color=Fore.MAGENTA) | 248 line.append(ahead_string, separator=' ', color=Fore.MAGENTA) |
| 235 line.append(center_separator, separator=' ') | 249 line.append(center_separator, separator=' ') |
| 236 line.append(behind_string, separator=' ', color=Fore.MAGENTA) | 250 line.append(behind_string, separator=' ', color=Fore.MAGENTA) |
| 237 line.append(back_separator) | 251 line.append(back_separator) |
| 238 | 252 |
| 239 # The Rietveld issue associated with the branch. | 253 # The Rietveld issue associated with the branch. |
| 240 if self.verbosity >= 2: | 254 if self.__status_info: |
| 241 import git_cl # avoid heavy import cost unless we need it | |
| 242 none_text = '' if self.__is_invalid_parent(branch) else 'None' | 255 none_text = '' if self.__is_invalid_parent(branch) else 'None' |
| 243 url = git_cl.Changelist( | 256 (url, color) = self.__status_info[branch] |
| 244 branchref=branch).GetIssueURL() if branch_hash else None | 257 line.append(url or none_text, color=color) |
| 245 line.append(url or none_text, color=Fore.BLUE if url else Fore.WHITE) | |
| 246 | 258 |
| 247 self.output.append(line) | 259 self.output.append(line) |
| 248 | 260 |
| 249 for child in sorted(self.__parent_map.pop(branch, ())): | 261 for child in sorted(self.__parent_map.pop(branch, ())): |
| 250 self.__append_branch(child, depth=depth + 1) | 262 self.__append_branch(child, depth=depth + 1) |
| 251 | 263 |
| 252 | 264 |
| 253 def main(argv): | 265 def main(argv): |
| 254 colorama.init() | 266 colorama.init() |
| 255 if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION: | 267 if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 269 opts = parser.parse_args(argv[1:]) | 281 opts = parser.parse_args(argv[1:]) |
| 270 | 282 |
| 271 mapper = BranchMapper() | 283 mapper = BranchMapper() |
| 272 mapper.verbosity = opts.v | 284 mapper.verbosity = opts.v |
| 273 mapper.output.nocolor = opts.nocolor | 285 mapper.output.nocolor = opts.nocolor |
| 274 mapper.start() | 286 mapper.start() |
| 275 print mapper.output.as_formatted_string() | 287 print mapper.output.as_formatted_string() |
| 276 | 288 |
| 277 if __name__ == '__main__': | 289 if __name__ == '__main__': |
| 278 sys.exit(main(sys.argv)) | 290 sys.exit(main(sys.argv)) |
| OLD | NEW |