OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 """ | |
3 Provides an augmented `git log --graph` view. In particular, it also annotates | |
4 commits with branches + tags that point to them. Items are colorized as follows: | |
5 * Cyan - Currently checked out branch | |
6 * Green - Local branch | |
7 * Red - Remote branches | |
8 * Magenta - Tags | |
9 * Blue background - The currently checked out commit | |
10 """ | |
11 import sys | |
12 | |
13 import subprocess2 | |
14 | |
15 from git_common import current_branch, branches, tags, config_list, GIT_EXE | |
16 | |
17 from third_party import colorama | |
18 | |
19 CYAN = colorama.Fore.CYAN | |
20 GREEN = colorama.Fore.GREEN | |
21 MAGENTA = colorama.Fore.MAGENTA | |
22 RED = colorama.Fore.RED | |
23 | |
24 BLUEBAK = colorama.Back.BLUE | |
25 | |
26 BRIGHT = colorama.Style.BRIGHT | |
27 RESET = colorama.Fore.RESET + colorama.Back.RESET + colorama.Style.RESET_ALL | |
28 | |
29 def main(): | |
30 colorama.init() | |
31 | |
iannucci
2014/03/12 00:12:21
oddly, this seems to be 'smart' and only emit colo
| |
32 map_extra = config_list('depot_tools.map_extra') | |
33 fmt = '%C(red bold)%h%x09%Creset%C(green)%d%Creset %C(yellow)%ad%Creset ~ %s' | |
34 log_proc = subprocess2.Popen( | |
35 [GIT_EXE, 'log', '--graph', '--full-history', '--branches', '--tags', | |
36 '--remotes', '--color', '--date=short', ('--pretty=format:' + fmt) | |
37 ] + map_extra + sys.argv[1:], | |
38 stdout=subprocess2.PIPE, | |
39 shell=False) | |
40 | |
41 current = current_branch() | |
42 all_branches = set(branches()) | |
43 if current in all_branches: | |
44 all_branches.remove(current) | |
45 all_tags = set(tags()) | |
46 try: | |
47 for line in log_proc.stdout.xreadlines(): | |
48 start = line.find(GREEN+' (') | |
49 end = line.find(')', start) | |
50 if start != -1 and end != -1: | |
51 start += len(GREEN) + 2 | |
52 branch_list = line[start:end].split(', ') | |
53 branches_str = '' | |
54 if branch_list: | |
55 colored_branches = [] | |
56 head_marker = '' | |
57 for b in branch_list: | |
58 if b == "HEAD": | |
59 head_marker = BLUEBAK+BRIGHT+'*' | |
60 continue | |
61 if b == current: | |
62 colored_branches.append(CYAN+BRIGHT+b+RESET) | |
63 current = None | |
64 elif b in all_branches: | |
65 colored_branches.append(GREEN+BRIGHT+b+RESET) | |
66 all_branches.remove(b) | |
67 elif b in all_tags: | |
68 colored_branches.append(MAGENTA+BRIGHT+b+RESET) | |
69 elif b.startswith('tag: '): | |
70 colored_branches.append(MAGENTA+BRIGHT+b[5:]+RESET) | |
71 else: | |
72 colored_branches.append(RED+b) | |
73 branches_str = '(%s) ' % ((GREEN+", ").join(colored_branches)+GREEN) | |
74 line = "%s%s%s" % (line[:start-1], branches_str, line[end+5:]) | |
75 if head_marker: | |
76 line = line.replace('*', head_marker, 1) | |
77 sys.stdout.write(line) | |
78 except (IOError, KeyboardInterrupt): | |
79 pass | |
80 return 0 | |
81 | |
82 | |
83 if __name__ == '__main__': | |
84 sys.exit(main()) | |
85 | |
OLD | NEW |