Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: git_map_branches.py

Issue 1851283002: Fix coloring madness in depot_tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Improve logic a bit Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « git_common.py ('k') | setup_color.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 * Green - a local branch 21 * Green - a local branch
22 * Blue - a 'branch-heads' branch 22 * Blue - a 'branch-heads' branch
23 * Magenta - a tag 23 * Magenta - a tag
24 * Magenta '{NO UPSTREAM}' - If you have local branches which do not track any 24 * Magenta '{NO UPSTREAM}' - If you have local branches which do not track any
25 upstream, then you will see this. 25 upstream, then you will see this.
26 """ 26 """
27 27
28 import argparse 28 import argparse
29 import collections 29 import collections
30 import os 30 import os
31 import subprocess2
31 import sys 32 import sys
32 import subprocess2
33
34 from third_party import colorama
35 from third_party.colorama import Fore, Style
36 33
37 from git_common import current_branch, upstream, tags, get_branches_info 34 from git_common import current_branch, upstream, tags, get_branches_info
38 from git_common import get_git_version, MIN_UPSTREAM_TRACK_GIT_VERSION, hash_one 35 from git_common import get_git_version, MIN_UPSTREAM_TRACK_GIT_VERSION, hash_one
39 from git_common import run 36 from git_common import run
40 37
38 import setup_color
39
40 from third_party.colorama import Fore, Style
41
41 DEFAULT_SEPARATOR = ' ' * 4 42 DEFAULT_SEPARATOR = ' ' * 4
42 43
43 44
44 class OutputManager(object): 45 class OutputManager(object):
45 """Manages a number of OutputLines and formats them into aligned columns.""" 46 """Manages a number of OutputLines and formats them into aligned columns."""
46 47
47 def __init__(self): 48 def __init__(self):
48 self.lines = [] 49 self.lines = []
49 self.nocolor = False 50 self.nocolor = False
50 self.max_column_lengths = [] 51 self.max_column_lengths = []
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if self.show_subject: 266 if self.show_subject:
266 line.append(run('log', '-n1', '--format=%s', branch)) 267 line.append(run('log', '-n1', '--format=%s', branch))
267 268
268 self.output.append(line) 269 self.output.append(line)
269 270
270 for child in sorted(self.__parent_map.pop(branch, ())): 271 for child in sorted(self.__parent_map.pop(branch, ())):
271 self.__append_branch(child, depth=depth + 1) 272 self.__append_branch(child, depth=depth + 1)
272 273
273 274
274 def main(argv): 275 def main(argv):
275 colorama.init(wrap="TERM" not in os.environ) 276 setup_color.init()
276 if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION: 277 if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION:
277 print >> sys.stderr, ( 278 print >> sys.stderr, (
278 'This tool will not show all tracking information for git version ' 279 'This tool will not show all tracking information for git version '
279 'earlier than ' + 280 'earlier than ' +
280 '.'.join(str(x) for x in MIN_UPSTREAM_TRACK_GIT_VERSION) + 281 '.'.join(str(x) for x in MIN_UPSTREAM_TRACK_GIT_VERSION) +
281 '. Please consider upgrading.') 282 '. Please consider upgrading.')
282 283
283 parser = argparse.ArgumentParser( 284 parser = argparse.ArgumentParser(
284 description='Print a a tree of all branches parented by their upstreams') 285 description='Print a a tree of all branches parented by their upstreams')
285 parser.add_argument('-v', action='count', 286 parser.add_argument('-v', action='count',
(...skipping 16 matching lines...) Expand all
302 mapper.start() 303 mapper.start()
303 print mapper.output.as_formatted_string() 304 print mapper.output.as_formatted_string()
304 return 0 305 return 0
305 306
306 if __name__ == '__main__': 307 if __name__ == '__main__':
307 try: 308 try:
308 sys.exit(main(sys.argv[1:])) 309 sys.exit(main(sys.argv[1:]))
309 except KeyboardInterrupt: 310 except KeyboardInterrupt:
310 sys.stderr.write('interrupted\n') 311 sys.stderr.write('interrupted\n')
311 sys.exit(1) 312 sys.exit(1)
OLDNEW
« no previous file with comments | « git_common.py ('k') | setup_color.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698