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

Side by Side Diff: git_map.py

Issue 184253003: Add git-reup and friends (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@freeze_thaw
Patch Set: fix pylint Created 6 years, 9 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_freezer.py ('k') | git_map_branches.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 """ 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 * Blue background - The currently checked out commit 14 * Blue background - The currently checked out commit
14 """ 15 """
16
15 import sys 17 import sys
16 18
17 import subprocess2 19 import subprocess2
18 20
19 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
20 23
21 from third_party import colorama 24 from third_party import colorama
22 25
23 CYAN = colorama.Fore.CYAN 26 CYAN = colorama.Fore.CYAN
24 GREEN = colorama.Fore.GREEN 27 GREEN = colorama.Fore.GREEN
25 MAGENTA = colorama.Fore.MAGENTA 28 MAGENTA = colorama.Fore.MAGENTA
26 RED = colorama.Fore.RED 29 RED = colorama.Fore.RED
30 WHITE = colorama.Fore.WHITE
27 31
28 BLUEBAK = colorama.Back.BLUE 32 BLUEBAK = colorama.Back.BLUE
29 33
30 BRIGHT = colorama.Style.BRIGHT 34 BRIGHT = colorama.Style.BRIGHT
31 RESET = colorama.Fore.RESET + colorama.Back.RESET + colorama.Style.RESET_ALL 35 RESET = colorama.Fore.RESET + colorama.Back.RESET + colorama.Style.RESET_ALL
32 36
37 # Git emits combined color
38 BRIGHT_RED = '\x1b[1;31m'
39
33 def main(): 40 def main():
34 map_extra = config_list('depot_tools.map_extra') 41 map_extra = config_list('depot_tools.map_extra')
35 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'
36 log_proc = subprocess2.Popen( 43 log_proc = subprocess2.Popen(
37 [GIT_EXE, 'log', '--graph', '--full-history', '--branches', '--tags', 44 [GIT_EXE, 'log', '--graph', '--full-history', '--branches', '--tags',
38 '--remotes', '--color=always', '--date=short', ('--pretty=format:' + fmt) 45 '--remotes', '--color=always', '--date=short', ('--pretty=format:' + fmt)
39 ] + map_extra + sys.argv[1:], 46 ] + map_extra + sys.argv[1:],
40 stdout=subprocess2.PIPE, 47 stdout=subprocess2.PIPE,
41 shell=False) 48 shell=False)
42 49
50 merge_base_map = branch_config_map('base')
43 current = current_branch() 51 current = current_branch()
44 all_branches = set(branches()) 52 all_branches = set(branches())
45 if current in all_branches: 53 if current in all_branches:
46 all_branches.remove(current) 54 all_branches.remove(current)
47 all_tags = set(tags()) 55 all_tags = set(tags())
48 try: 56 try:
49 for line in log_proc.stdout.xreadlines(): 57 for line in log_proc.stdout.xreadlines():
58 if merge_base_map:
59 commit = line[line.find(BRIGHT_RED)+len(BRIGHT_RED):line.find('\t')]
60 base_for_branches = set()
61 for branch, sha in merge_base_map.iteritems():
62 if sha.startswith(commit):
63 base_for_branches.add(branch)
64 if base_for_branches:
65 newline = '\r\n' if line.endswith('\r\n') else '\n'
66 line = line.rstrip(newline)
67 line += ''.join(
68 (BRIGHT, WHITE, ' <(%s)' % (', '.join(base_for_branches)),
69 newline))
70 for b in base_for_branches:
71 del merge_base_map[b]
72
50 start = line.find(GREEN+' (') 73 start = line.find(GREEN+' (')
51 end = line.find(')', start) 74 end = line.find(')', start)
52 if start != -1 and end != -1: 75 if start != -1 and end != -1:
53 start += len(GREEN) + 2 76 start += len(GREEN) + 2
54 branch_list = line[start:end].split(', ') 77 branch_list = line[start:end].split(', ')
55 branches_str = '' 78 branches_str = ''
56 if branch_list: 79 if branch_list:
57 colored_branches = [] 80 colored_branches = []
58 head_marker = '' 81 head_marker = ''
59 for b in branch_list: 82 for b in branch_list:
(...skipping 21 matching lines...) Expand all
81 pass 104 pass
82 finally: 105 finally:
83 sys.stderr.close() 106 sys.stderr.close()
84 sys.stdout.close() 107 sys.stdout.close()
85 return 0 108 return 0
86 109
87 110
88 if __name__ == '__main__': 111 if __name__ == '__main__':
89 sys.exit(main()) 112 sys.exit(main())
90 113
OLDNEW
« no previous file with comments | « git_freezer.py ('k') | git_map_branches.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698