Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
|
agable
2014/02/28 19:54:58
Needs a module level docstring. All of these do, i
iannucci
2014/03/06 00:18:39
Right. Done.
| |
| 2 import sys | |
| 3 | |
| 4 import subprocess2 | |
| 5 | |
| 6 from git_common import current_branch, branches, tags, config_list, GIT_EXE | |
| 7 | |
| 8 from third_party import colorama | |
| 9 | |
| 10 CYAN = colorama.Fore.CYAN | |
| 11 GREEN = colorama.Fore.GREEN | |
| 12 MAGENTA = colorama.Fore.MAGENTA | |
| 13 RED = colorama.Fore.RED | |
| 14 | |
| 15 BLUEBAK = colorama.Back.BLUE | |
| 16 | |
| 17 BRIGHT = colorama.Style.BRIGHT | |
| 18 RESET = colorama.Fore.RESET + colorama.Back.RESET + colorama.Style.RESET_ALL | |
| 19 | |
| 20 def main(): | |
| 21 colorama.init() | |
| 22 | |
| 23 map_extra = config_list('depot_tools.map_extra') | |
| 24 fmt = '%C(red bold)%h%x09%Creset%C(green)%d%Creset %C(yellow)%ad%Creset ~ %s' | |
| 25 log_proc = subprocess2.Popen( | |
| 26 [GIT_EXE, 'log', '--graph', '--full-history', '--branches', '--tags', | |
| 27 '--remotes', '--color', '--date=short', ('--pretty=format:' + fmt) | |
| 28 ] + map_extra + sys.argv[1:], | |
| 29 stdout=subprocess2.PIPE, | |
| 30 shell=False) | |
| 31 | |
| 32 current = current_branch() | |
| 33 all_branches = set(branches()) | |
| 34 if current in all_branches: | |
| 35 all_branches.remove(current) | |
| 36 all_tags = set(tags()) | |
| 37 try: | |
| 38 for line in log_proc.stdout.xreadlines(): | |
| 39 start = line.find(GREEN+' (') | |
| 40 end = line.find(')', start) | |
| 41 if start != -1 and end != -1: | |
| 42 start += len(GREEN) + 2 | |
| 43 branch_list = line[start:end].split(', ') | |
| 44 branches_str = '' | |
| 45 if branch_list: | |
| 46 colored_branches = [] | |
| 47 head_marker = '' | |
| 48 for b in branch_list: | |
| 49 if b == "HEAD": | |
| 50 head_marker = BLUEBAK+BRIGHT+'*' | |
| 51 continue | |
| 52 if b == current: | |
| 53 colored_branches.append(CYAN+BRIGHT+b+RESET) | |
| 54 current = None | |
| 55 elif b in all_branches: | |
| 56 colored_branches.append(GREEN+BRIGHT+b+RESET) | |
| 57 all_branches.remove(b) | |
| 58 elif b in all_tags: | |
| 59 colored_branches.append(MAGENTA+BRIGHT+b+RESET) | |
| 60 all_tags.remove(b) | |
| 61 else: | |
| 62 colored_branches.append(RED+b) | |
| 63 branches_str = '(%s) ' % ((GREEN+", ").join(colored_branches)+GREEN) | |
| 64 line = "%s%s%s" % (line[:start-1], branches_str, line[end+5:]) | |
| 65 if head_marker: | |
| 66 line = line.replace('*', head_marker, 1) | |
| 67 sys.stdout.write(line) | |
| 68 except (IOError, KeyboardInterrupt): | |
| 69 pass | |
| 70 return 0 | |
| 71 | |
| 72 | |
| 73 if __name__ == '__main__': | |
| 74 sys.exit(main()) | |
| 75 | |
| OLD | NEW |