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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 self.__append_branch(root) | 167 self.__append_branch(root) |
168 else: | 168 else: |
169 no_branches = OutputLine() | 169 no_branches = OutputLine() |
170 no_branches.append('No User Branches') | 170 no_branches.append('No User Branches') |
171 self.output.append(no_branches) | 171 self.output.append(no_branches) |
172 | 172 |
173 def __is_invalid_parent(self, parent): | 173 def __is_invalid_parent(self, parent): |
174 return not parent or parent in self.__gone_branches | 174 return not parent or parent in self.__gone_branches |
175 | 175 |
176 def __color_for_branch(self, branch, branch_hash): | 176 def __color_for_branch(self, branch, branch_hash): |
177 if branch.startswith('origin'): | 177 if branch.startswith('origin/'): |
178 color = Fore.RED | 178 color = Fore.RED |
179 elif branch.startswith('branch-heads'): | 179 elif branch.startswith('branch-heads'): |
180 color = Fore.BLUE | 180 color = Fore.BLUE |
181 elif self.__is_invalid_parent(branch) or branch in self.__tag_set: | 181 elif self.__is_invalid_parent(branch) or branch in self.__tag_set: |
182 color = Fore.MAGENTA | 182 color = Fore.MAGENTA |
183 elif self.__current_hash.startswith(branch_hash): | 183 elif self.__current_hash.startswith(branch_hash): |
184 color = Fore.CYAN | 184 color = Fore.CYAN |
185 else: | 185 else: |
186 color = Fore.GREEN | 186 color = Fore.GREEN |
187 | 187 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 mapper.start() | 301 mapper.start() |
302 print mapper.output.as_formatted_string() | 302 print mapper.output.as_formatted_string() |
303 return 0 | 303 return 0 |
304 | 304 |
305 if __name__ == '__main__': | 305 if __name__ == '__main__': |
306 try: | 306 try: |
307 sys.exit(main(sys.argv[1:])) | 307 sys.exit(main(sys.argv[1:])) |
308 except KeyboardInterrupt: | 308 except KeyboardInterrupt: |
309 sys.stderr.write('interrupted\n') | 309 sys.stderr.write('interrupted\n') |
310 sys.exit(1) | 310 sys.exit(1) |
OLD | NEW |