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

Side by Side Diff: git_map_branches.py

Issue 938583002: Make git-map-branches -vvv show CL status colors. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: address comments Created 5 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_cl.py ('k') | no next file » | 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 class BranchMapper(object): 102 class BranchMapper(object):
103 """A class which constructs output representing the tree's branch structure. 103 """A class which constructs output representing the tree's branch structure.
104 104
105 Attributes: 105 Attributes:
106 __branches_info: a map of branches to their BranchesInfo objects which 106 __branches_info: a map of branches to their BranchesInfo objects which
107 consist of the branch hash, upstream and ahead/behind status. 107 consist of the branch hash, upstream and ahead/behind status.
108 __gone_branches: a set of upstreams which are not fetchable by git""" 108 __gone_branches: a set of upstreams which are not fetchable by git"""
109 109
110 def __init__(self): 110 def __init__(self):
111 self.verbosity = 0 111 self.verbosity = 0
112 self.maxjobs = 0
112 self.output = OutputManager() 113 self.output = OutputManager()
113 self.__gone_branches = set() 114 self.__gone_branches = set()
114 self.__branches_info = None 115 self.__branches_info = None
115 self.__parent_map = collections.defaultdict(list) 116 self.__parent_map = collections.defaultdict(list)
116 self.__current_branch = None 117 self.__current_branch = None
117 self.__current_hash = None 118 self.__current_hash = None
118 self.__tag_set = None 119 self.__tag_set = None
120 self.__status_info = {}
119 121
120 def start(self): 122 def start(self):
121 self.__branches_info = get_branches_info( 123 self.__branches_info = get_branches_info(
122 include_tracking_status=self.verbosity >= 1) 124 include_tracking_status=self.verbosity >= 1)
125 if (self.verbosity >= 2):
126 # Avoid heavy import unless necessary.
127 from git_cl import get_cl_statuses
128
129 status_info = get_cl_statuses(self.__branches_info.keys(),
130 fine_grained=self.verbosity > 2,
131 max_processes=self.maxjobs)
132
133 for _ in xrange(len(self.__branches_info)):
134 # This is a blocking get which waits for the remote CL status to be
135 # retrieved.
136 (branch, url, color) = status_info.next()
137 self.__status_info[branch] = (url, color);
138
123 roots = set() 139 roots = set()
124 140
125 # A map of parents to a list of their children. 141 # A map of parents to a list of their children.
126 for branch, branch_info in self.__branches_info.iteritems(): 142 for branch, branch_info in self.__branches_info.iteritems():
127 if not branch_info: 143 if not branch_info:
128 continue 144 continue
129 145
130 parent = branch_info.upstream 146 parent = branch_info.upstream
131 if not self.__branches_info[parent]: 147 if not self.__branches_info[parent]:
132 branch_upstream = upstream(branch) 148 branch_upstream = upstream(branch)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 center_separator = '|' 247 center_separator = '|'
232 248
233 line.append(front_separator, separator=' ') 249 line.append(front_separator, separator=' ')
234 line.append(ahead_string, separator=' ', color=Fore.MAGENTA) 250 line.append(ahead_string, separator=' ', color=Fore.MAGENTA)
235 line.append(center_separator, separator=' ') 251 line.append(center_separator, separator=' ')
236 line.append(behind_string, separator=' ', color=Fore.MAGENTA) 252 line.append(behind_string, separator=' ', color=Fore.MAGENTA)
237 line.append(back_separator) 253 line.append(back_separator)
238 254
239 # The Rietveld issue associated with the branch. 255 # The Rietveld issue associated with the branch.
240 if self.verbosity >= 2: 256 if self.verbosity >= 2:
241 import git_cl # avoid heavy import cost unless we need it
242 none_text = '' if self.__is_invalid_parent(branch) else 'None' 257 none_text = '' if self.__is_invalid_parent(branch) else 'None'
243 url = git_cl.Changelist( 258 (url, color) = self.__status_info[branch]
244 branchref=branch).GetIssueURL() if branch_hash else None 259 line.append(url or none_text, color=color)
245 line.append(url or none_text, color=Fore.BLUE if url else Fore.WHITE)
246 260
247 self.output.append(line) 261 self.output.append(line)
248 262
249 for child in sorted(self.__parent_map.pop(branch, ())): 263 for child in sorted(self.__parent_map.pop(branch, ())):
250 self.__append_branch(child, depth=depth + 1) 264 self.__append_branch(child, depth=depth + 1)
251 265
252 266
253 def main(argv): 267 def main(argv):
254 colorama.init() 268 colorama.init()
255 if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION: 269 if get_git_version() < MIN_UPSTREAM_TRACK_GIT_VERSION:
256 print >> sys.stderr, ( 270 print >> sys.stderr, (
257 'This tool will not show all tracking information for git version ' 271 'This tool will not show all tracking information for git version '
258 'earlier than ' + 272 'earlier than ' +
259 '.'.join(str(x) for x in MIN_UPSTREAM_TRACK_GIT_VERSION) + 273 '.'.join(str(x) for x in MIN_UPSTREAM_TRACK_GIT_VERSION) +
260 '. Please consider upgrading.') 274 '. Please consider upgrading.')
261 275
262 parser = argparse.ArgumentParser( 276 parser = argparse.ArgumentParser(
263 description='Print a a tree of all branches parented by their upstreams') 277 description='Print a a tree of all branches parented by their upstreams')
264 parser.add_argument('-v', action='count', 278 parser.add_argument('-v', action='count',
265 help='Display branch hash and Rietveld URL') 279 help='Display branch hash and Rietveld URL')
266 parser.add_argument('--no-color', action='store_true', dest='nocolor', 280 parser.add_argument('--no-color', action='store_true', dest='nocolor',
267 help='Turn off colors.') 281 help='Turn off colors.')
282 parser.add_argument(
283 '-j', '--maxjobs', action='store', type=int,
284 help='The number of jobs to use when retrieving review status')
268 285
269 opts = parser.parse_args(argv) 286 opts = parser.parse_args(argv)
270 287
271 mapper = BranchMapper() 288 mapper = BranchMapper()
272 mapper.verbosity = opts.v 289 mapper.verbosity = opts.v
273 mapper.output.nocolor = opts.nocolor 290 mapper.output.nocolor = opts.nocolor
291 mapper.maxjobs = opts.maxjobs
274 mapper.start() 292 mapper.start()
275 print mapper.output.as_formatted_string() 293 print mapper.output.as_formatted_string()
276 return 0 294 return 0
277 295
278 if __name__ == '__main__': 296 if __name__ == '__main__':
279 try: 297 try:
280 sys.exit(main(sys.argv[1:])) 298 sys.exit(main(sys.argv[1:]))
281 except KeyboardInterrupt: 299 except KeyboardInterrupt:
282 sys.stderr.write('interrupted\n') 300 sys.stderr.write('interrupted\n')
283 sys.exit(1) 301 sys.exit(1)
OLDNEW
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698