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 | |
|
iannucci
2015/03/03 01:00:14
why not default to `{}`?
calamity
2015/03/03 04:58:12
Done.
| |
| 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 = {} | |
|
iannucci
2015/03/03 01:00:14
then you can skip this
calamity
2015/03/03 04:58:12
Done.
| |
| 129 status_info = get_cl_statuses(self.__branches_info.keys(), | |
| 130 self.verbosity == 2) | |
| 131 | |
| 132 for _ in xrange(len(self.__branches_info)): | |
| 133 # This is a blocking get which waits for the remote CL status to be | |
| 134 # retrieved. | |
| 135 (branch, url, color) = status_info.get() | |
| 136 self.__status_info[branch] = (url, color); | |
| 137 | |
| 123 roots = set() | 138 roots = set() |
| 124 | 139 |
| 125 # A map of parents to a list of their children. | 140 # A map of parents to a list of their children. |
| 126 for branch, branch_info in self.__branches_info.iteritems(): | 141 for branch, branch_info in self.__branches_info.iteritems(): |
| 127 if not branch_info: | 142 if not branch_info: |
| 128 continue | 143 continue |
| 129 | 144 |
| 130 parent = branch_info.upstream | 145 parent = branch_info.upstream |
| 131 if not self.__branches_info[parent]: | 146 if not self.__branches_info[parent]: |
| 132 branch_upstream = upstream(branch) | 147 branch_upstream = upstream(branch) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 if ahead and behind: | 245 if ahead and behind: |
| 231 center_separator = '|' | 246 center_separator = '|' |
| 232 | 247 |
| 233 line.append(front_separator, separator=' ') | 248 line.append(front_separator, separator=' ') |
| 234 line.append(ahead_string, separator=' ', color=Fore.MAGENTA) | 249 line.append(ahead_string, separator=' ', color=Fore.MAGENTA) |
| 235 line.append(center_separator, separator=' ') | 250 line.append(center_separator, separator=' ') |
| 236 line.append(behind_string, separator=' ', color=Fore.MAGENTA) | 251 line.append(behind_string, separator=' ', color=Fore.MAGENTA) |
| 237 line.append(back_separator) | 252 line.append(back_separator) |
| 238 | 253 |
| 239 # The Rietveld issue associated with the branch. | 254 # The Rietveld issue associated with the branch. |
| 240 if self.verbosity >= 2: | 255 if self.__status_info: |
|
iannucci
2015/03/03 01:00:14
and this would still work, but in general you woul
calamity
2015/03/03 04:58:12
Reverted to a verbosity check.
| |
| 241 import git_cl # avoid heavy import cost unless we need it | |
| 242 none_text = '' if self.__is_invalid_parent(branch) else 'None' | 256 none_text = '' if self.__is_invalid_parent(branch) else 'None' |
| 243 url = git_cl.Changelist( | 257 (url, color) = self.__status_info[branch] |
| 244 branchref=branch).GetIssueURL() if branch_hash else None | 258 line.append(url or none_text, color=color) |
| 245 line.append(url or none_text, color=Fore.BLUE if url else Fore.WHITE) | |
| 246 | 259 |
| 247 self.output.append(line) | 260 self.output.append(line) |
| 248 | 261 |
| 249 for child in sorted(self.__parent_map.pop(branch, ())): | 262 for child in sorted(self.__parent_map.pop(branch, ())): |
| 250 self.__append_branch(child, depth=depth + 1) | 263 self.__append_branch(child, depth=depth + 1) |
| 251 | 264 |
| 252 | 265 |
| 253 def main(argv): | 266 def main(argv): |
| 254 colorama.init() | 267 colorama.init() |
| 255 if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION: | 268 if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 274 mapper.start() | 287 mapper.start() |
| 275 print mapper.output.as_formatted_string() | 288 print mapper.output.as_formatted_string() |
| 276 return 0 | 289 return 0 |
| 277 | 290 |
| 278 if __name__ == '__main__': | 291 if __name__ == '__main__': |
| 279 try: | 292 try: |
| 280 sys.exit(main(sys.argv[1:])) | 293 sys.exit(main(sys.argv[1:])) |
| 281 except KeyboardInterrupt: | 294 except KeyboardInterrupt: |
| 282 sys.stderr.write('interrupted\n') | 295 sys.stderr.write('interrupted\n') |
| 283 sys.exit(1) | 296 sys.exit(1) |
| OLD | NEW |