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

Side by Side Diff: git_cl.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: rebase, address comment, remove unused var 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 | « no previous file | git_map_branches.py » ('j') | git_map_branches.py » ('J')
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 (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 return { 1331 return {
1332 'unsent': Fore.RED, 1332 'unsent': Fore.RED,
1333 'waiting': Fore.BLUE, 1333 'waiting': Fore.BLUE,
1334 'reply': Fore.YELLOW, 1334 'reply': Fore.YELLOW,
1335 'lgtm': Fore.GREEN, 1335 'lgtm': Fore.GREEN,
1336 'commit': Fore.MAGENTA, 1336 'commit': Fore.MAGENTA,
1337 'closed': Fore.CYAN, 1337 'closed': Fore.CYAN,
1338 'error': Fore.WHITE, 1338 'error': Fore.WHITE,
1339 }.get(status, Fore.WHITE) 1339 }.get(status, Fore.WHITE)
1340 1340
1341 def get_cl_statuses(branches, fast=False):
1342 """Returns a blocking Queue of (branch, issue, color) for provided branches.
1343
1344 If fast is false, this will spawn len(branches) number of threads and fetch
iannucci 2015/03/03 01:00:14 I think this is a bit misleading (and 'fast' is a
calamity 2015/03/03 04:58:12 Done. It spawns as many jobs as there are branches
1345 the remote cl statuses.
1346 """
1347 # Adhoc thread pool to request data concurrently.
1348 output = Queue.Queue()
1349
1350 # Silence upload.py otherwise it becomes unweldly.
1351 upload.verbosity = 0
1352
1353 if not fast:
1354 def fetch(b):
1355 """Fetches information for an issue and returns (branch, issue, color)."""
1356 c = Changelist(branchref=b)
1357 i = c.GetIssueURL()
1358 status = c.GetStatus()
1359 color = color_for_status(status)
1360
1361 if i and (not status or status == 'error'):
1362 # The issue probably doesn't exist anymore.
1363 i += ' (broken)'
1364
1365 output.put((b, i, color))
1366
1367 # Process one branch synchronously to work through authentication, then
1368 # spawn threads to process all the other branches in parallel.
1369 if branches:
1370 fetch(branches[0])
1371 threads = [
1372 threading.Thread(target=fetch, args=(b,)) for b in branches[1:]]
1373 for t in threads:
1374 t.daemon = True
1375 t.start()
1376 else:
1377 # Do not use GetApprovingReviewers(), since it requires an HTTP request.
1378 for b in branches:
1379 c = Changelist(branchref=b)
1380 url = c.GetIssueURL()
1381 output.put((b, url, Fore.BLUE if url else Fore.WHITE))
1382
1383 return output
1341 1384
1342 def CMDstatus(parser, args): 1385 def CMDstatus(parser, args):
1343 """Show status of changelists. 1386 """Show status of changelists.
1344 1387
1345 Colors are used to tell the state of the CL unless --fast is used: 1388 Colors are used to tell the state of the CL unless --fast is used:
1346 - Red not sent for review or broken 1389 - Red not sent for review or broken
1347 - Blue waiting for review 1390 - Blue waiting for review
1348 - Yellow waiting for you to reply to review 1391 - Yellow waiting for you to reply to review
1349 - Green LGTM'ed 1392 - Green LGTM'ed
1350 - Magenta in the commit queue 1393 - Magenta in the commit queue
(...skipping 29 matching lines...) Expand all
1380 1423
1381 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) 1424 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads'])
1382 if not branches: 1425 if not branches:
1383 print('No local branch found.') 1426 print('No local branch found.')
1384 return 0 1427 return 0
1385 1428
1386 changes = (Changelist(branchref=b) for b in branches.splitlines()) 1429 changes = (Changelist(branchref=b) for b in branches.splitlines())
1387 branches = [c.GetBranch() for c in changes] 1430 branches = [c.GetBranch() for c in changes]
1388 alignment = max(5, max(len(b) for b in branches)) 1431 alignment = max(5, max(len(b) for b in branches))
1389 print 'Branches associated with reviews:' 1432 print 'Branches associated with reviews:'
1390 # Adhoc thread pool to request data concurrently. 1433 output = get_cl_statuses(branches, options.fast)
1391 output = Queue.Queue()
1392
1393 # Silence upload.py otherwise it becomes unweldly.
1394 upload.verbosity = 0
1395
1396 if not options.fast:
1397 def fetch(b):
1398 """Fetches information for an issue and returns (branch, issue, color)."""
1399 c = Changelist(branchref=b)
1400 i = c.GetIssueURL()
1401 status = c.GetStatus()
1402 color = color_for_status(status)
1403
1404 if i and (not status or status == 'error'):
1405 # The issue probably doesn't exist anymore.
1406 i += ' (broken)'
1407
1408 output.put((b, i, color))
1409
1410 # Process one branch synchronously to work through authentication, then
1411 # spawn threads to process all the other branches in parallel.
1412 if branches:
1413 fetch(branches[0])
1414 threads = [
1415 threading.Thread(target=fetch, args=(b,)) for b in branches[1:]]
1416 for t in threads:
1417 t.daemon = True
1418 t.start()
1419 else:
1420 # Do not use GetApprovingReviewers(), since it requires an HTTP request.
1421 for b in branches:
1422 c = Changelist(branchref=b)
1423 url = c.GetIssueURL()
1424 output.put((b, url, Fore.BLUE if url else Fore.WHITE))
1425 1434
1426 tmp = {} 1435 tmp = {}
1427 alignment = max(5, max(len(ShortBranchName(b)) for b in branches)) 1436 alignment = max(5, max(len(ShortBranchName(b)) for b in branches))
1428 for branch in sorted(branches): 1437 for branch in sorted(branches):
1429 while branch not in tmp: 1438 while branch not in tmp:
1430 b, i, color = output.get() 1439 b, i, color = output.get()
1431 tmp[b] = (i, color) 1440 tmp[b] = (i, color)
1432 issue, color = tmp.pop(branch) 1441 issue, color = tmp.pop(branch)
1433 reset = Fore.RESET 1442 reset = Fore.RESET
1434 if not sys.stdout.isatty(): 1443 if not sys.stdout.isatty():
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after
3094 if __name__ == '__main__': 3103 if __name__ == '__main__':
3095 # These affect sys.stdout so do it outside of main() to simplify mocks in 3104 # These affect sys.stdout so do it outside of main() to simplify mocks in
3096 # unit testing. 3105 # unit testing.
3097 fix_encoding.fix_encoding() 3106 fix_encoding.fix_encoding()
3098 colorama.init() 3107 colorama.init()
3099 try: 3108 try:
3100 sys.exit(main(sys.argv[1:])) 3109 sys.exit(main(sys.argv[1:]))
3101 except KeyboardInterrupt: 3110 except KeyboardInterrupt:
3102 sys.stderr.write('interrupted\n') 3111 sys.stderr.write('interrupted\n')
3103 sys.exit(1) 3112 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | git_map_branches.py » ('j') | git_map_branches.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698