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 """ | 6 """ |
7 Provides an augmented `git log --graph` view. In particular, it also annotates | 7 Provides an augmented `git log --graph` view. In particular, it also annotates |
8 commits with branches + tags that point to them. Items are colorized as follows: | 8 commits with branches + tags that point to them. Items are colorized as follows: |
9 * Cyan - Currently checked out branch | 9 * Cyan - Currently checked out branch |
10 * Green - Local branch | 10 * Green - Local branch |
11 * Red - Remote branches | 11 * Red - Remote branches |
12 * Magenta - Tags | 12 * Magenta - Tags |
13 * White - Merge Base Markers | 13 * White - Merge Base Markers |
14 * Blue background - The currently checked out commit | 14 * Blue background - The currently checked out commit |
15 """ | 15 """ |
16 | 16 |
17 import sys | 17 import sys |
18 | 18 |
19 import subprocess2 | 19 import subprocess2 |
20 | 20 |
21 from git_common import current_branch, branches, tags, config_list, GIT_EXE | 21 from git_common import current_branch, branches, tags, config_list, GIT_EXE |
22 from git_common import branch_config_map, root | 22 from git_common import get_or_create_merge_base, root |
23 | 23 |
24 from third_party import colorama | 24 from third_party import colorama |
25 | 25 |
26 CYAN = colorama.Fore.CYAN | 26 CYAN = colorama.Fore.CYAN |
27 GREEN = colorama.Fore.GREEN | 27 GREEN = colorama.Fore.GREEN |
28 MAGENTA = colorama.Fore.MAGENTA | 28 MAGENTA = colorama.Fore.MAGENTA |
29 RED = colorama.Fore.RED | 29 RED = colorama.Fore.RED |
30 WHITE = colorama.Fore.WHITE | 30 WHITE = colorama.Fore.WHITE |
31 | 31 |
32 BLUEBAK = colorama.Back.BLUE | 32 BLUEBAK = colorama.Back.BLUE |
33 | 33 |
34 BRIGHT = colorama.Style.BRIGHT | 34 BRIGHT = colorama.Style.BRIGHT |
35 RESET = colorama.Fore.RESET + colorama.Back.RESET + colorama.Style.RESET_ALL | 35 RESET = colorama.Fore.RESET + colorama.Back.RESET + colorama.Style.RESET_ALL |
36 | 36 |
37 # Git emits combined color | 37 # Git emits combined color |
38 BRIGHT_RED = '\x1b[1;31m' | 38 BRIGHT_RED = '\x1b[1;31m' |
39 | 39 |
40 def main(): | 40 def main(): |
41 map_extra = config_list('depot_tools.map_extra') | 41 map_extra = config_list('depot_tools.map_extra') |
42 fmt = '%C(red bold)%h%x09%Creset%C(green)%d%Creset %C(yellow)%ad%Creset ~ %s' | 42 fmt = '%C(red bold)%h%x09%Creset%C(green)%d%Creset %C(yellow)%ad%Creset ~ %s' |
43 log_proc = subprocess2.Popen( | 43 log_proc = subprocess2.Popen( |
44 [GIT_EXE, 'log', '--graph', '--branches', '--tags', root(), | 44 [GIT_EXE, 'log', '--graph', '--branches', '--tags', root(), |
45 '--color=always', '--date=short', ('--pretty=format:' + fmt) | 45 '--color=always', '--date=short', ('--pretty=format:' + fmt) |
46 ] + map_extra + sys.argv[1:], | 46 ] + map_extra + sys.argv[1:], |
47 stdout=subprocess2.PIPE, | 47 stdout=subprocess2.PIPE, |
48 shell=False) | 48 shell=False) |
49 | 49 |
50 merge_base_map = branch_config_map('base') | |
51 current = current_branch() | 50 current = current_branch() |
52 all_branches = set(branches()) | 51 all_branches = set(branches()) |
| 52 merge_base_map = {b: get_or_create_merge_base(b) for b in all_branches} |
53 if current in all_branches: | 53 if current in all_branches: |
54 all_branches.remove(current) | 54 all_branches.remove(current) |
55 all_tags = set(tags()) | 55 all_tags = set(tags()) |
56 try: | 56 try: |
57 for line in log_proc.stdout.xreadlines(): | 57 for line in log_proc.stdout.xreadlines(): |
58 if merge_base_map: | 58 if merge_base_map: |
59 commit = line[line.find(BRIGHT_RED)+len(BRIGHT_RED):line.find('\t')] | 59 commit = line[line.find(BRIGHT_RED)+len(BRIGHT_RED):line.find('\t')] |
60 base_for_branches = set() | 60 base_for_branches = set() |
61 for branch, sha in merge_base_map.iteritems(): | 61 for branch, sha in merge_base_map.iteritems(): |
62 if sha.startswith(commit): | 62 if sha.startswith(commit): |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 pass | 104 pass |
105 finally: | 105 finally: |
106 sys.stderr.close() | 106 sys.stderr.close() |
107 sys.stdout.close() | 107 sys.stdout.close() |
108 return 0 | 108 return 0 |
109 | 109 |
110 | 110 |
111 if __name__ == '__main__': | 111 if __name__ == '__main__': |
112 sys.exit(main()) | 112 sys.exit(main()) |
113 | 113 |
OLD | NEW |