| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 self.__current_branch = None | 121 self.__current_branch = None |
| 122 self.__current_hash = None | 122 self.__current_hash = None |
| 123 self.__tag_set = None | 123 self.__tag_set = None |
| 124 self.__status_info = {} | 124 self.__status_info = {} |
| 125 | 125 |
| 126 def start(self): | 126 def start(self): |
| 127 self.__branches_info = get_branches_info( | 127 self.__branches_info = get_branches_info( |
| 128 include_tracking_status=self.verbosity >= 1) | 128 include_tracking_status=self.verbosity >= 1) |
| 129 if (self.verbosity >= 2): | 129 if (self.verbosity >= 2): |
| 130 # Avoid heavy import unless necessary. | 130 # Avoid heavy import unless necessary. |
| 131 from git_cl import get_cl_statuses, color_for_status | 131 from git_cl import get_cl_statuses, color_for_status, Changelist |
| 132 | 132 |
| 133 status_info = get_cl_statuses(self.__branches_info.keys(), | 133 change_cls = [Changelist(branchref='refs/heads/'+b) |
| 134 for b in self.__branches_info.keys() if b] |
| 135 status_info = get_cl_statuses(change_cls, |
| 134 fine_grained=self.verbosity > 2, | 136 fine_grained=self.verbosity > 2, |
| 135 max_processes=self.maxjobs) | 137 max_processes=self.maxjobs) |
| 136 | 138 |
| 137 for _ in xrange(len(self.__branches_info)): | 139 # This is a blocking get which waits for the remote CL status to be |
| 138 # This is a blocking get which waits for the remote CL status to be | 140 # retrieved. |
| 139 # retrieved. | 141 for cl, status in status_info: |
| 140 (branch, url, status) = status_info.next() | 142 self.__status_info[cl.GetBranch()] = (cl.GetIssueURL(), |
| 141 self.__status_info[branch] = (url, color_for_status(status)) | 143 color_for_status(status)) |
| 142 | 144 |
| 143 roots = set() | 145 roots = set() |
| 144 | 146 |
| 145 # A map of parents to a list of their children. | 147 # A map of parents to a list of their children. |
| 146 for branch, branch_info in self.__branches_info.iteritems(): | 148 for branch, branch_info in self.__branches_info.iteritems(): |
| 147 if not branch_info: | 149 if not branch_info: |
| 148 continue | 150 continue |
| 149 | 151 |
| 150 parent = branch_info.upstream | 152 parent = branch_info.upstream |
| 151 if not self.__branches_info[parent]: | 153 if not self.__branches_info[parent]: |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 center_separator = '|' | 253 center_separator = '|' |
| 252 | 254 |
| 253 line.append(front_separator, separator=' ') | 255 line.append(front_separator, separator=' ') |
| 254 line.append(ahead_string, separator=' ', color=Fore.MAGENTA) | 256 line.append(ahead_string, separator=' ', color=Fore.MAGENTA) |
| 255 line.append(center_separator, separator=' ') | 257 line.append(center_separator, separator=' ') |
| 256 line.append(behind_string, separator=' ', color=Fore.MAGENTA) | 258 line.append(behind_string, separator=' ', color=Fore.MAGENTA) |
| 257 line.append(back_separator) | 259 line.append(back_separator) |
| 258 | 260 |
| 259 # The Rietveld issue associated with the branch. | 261 # The Rietveld issue associated with the branch. |
| 260 if self.verbosity >= 2: | 262 if self.verbosity >= 2: |
| 261 none_text = '' if self.__is_invalid_parent(branch) else 'None' | 263 (url, color) = ('', '') if self.__is_invalid_parent(branch) \ |
| 262 (url, color) = self.__status_info[branch] | 264 else self.__status_info[branch] |
| 263 line.append(url or none_text, color=color) | 265 line.append(url or '', color=color) |
| 264 | 266 |
| 265 # The subject of the most recent commit on the branch. | 267 # The subject of the most recent commit on the branch. |
| 266 if self.show_subject: | 268 if self.show_subject: |
| 267 line.append(run('log', '-n1', '--format=%s', branch)) | 269 line.append(run('log', '-n1', '--format=%s', branch)) |
| 268 | 270 |
| 269 self.output.append(line) | 271 self.output.append(line) |
| 270 | 272 |
| 271 for child in sorted(self.__parent_map.pop(branch, ())): | 273 for child in sorted(self.__parent_map.pop(branch, ())): |
| 272 self.__append_branch(child, depth=depth + 1) | 274 self.__append_branch(child, depth=depth + 1) |
| 273 | 275 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 303 mapper.start() | 305 mapper.start() |
| 304 print mapper.output.as_formatted_string() | 306 print mapper.output.as_formatted_string() |
| 305 return 0 | 307 return 0 |
| 306 | 308 |
| 307 if __name__ == '__main__': | 309 if __name__ == '__main__': |
| 308 try: | 310 try: |
| 309 sys.exit(main(sys.argv[1:])) | 311 sys.exit(main(sys.argv[1:])) |
| 310 except KeyboardInterrupt: | 312 except KeyboardInterrupt: |
| 311 sys.stderr.write('interrupted\n') | 313 sys.stderr.write('interrupted\n') |
| 312 sys.exit(1) | 314 sys.exit(1) |
| OLD | NEW |