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

Side by Side Diff: git_cl.py

Issue 1172223002: Added textual status output to git-cl-status (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 (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 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 return { 1450 return {
1451 'unsent': Fore.RED, 1451 'unsent': Fore.RED,
1452 'waiting': Fore.BLUE, 1452 'waiting': Fore.BLUE,
1453 'reply': Fore.YELLOW, 1453 'reply': Fore.YELLOW,
1454 'lgtm': Fore.GREEN, 1454 'lgtm': Fore.GREEN,
1455 'commit': Fore.MAGENTA, 1455 'commit': Fore.MAGENTA,
1456 'closed': Fore.CYAN, 1456 'closed': Fore.CYAN,
1457 'error': Fore.WHITE, 1457 'error': Fore.WHITE,
1458 }.get(status, Fore.WHITE) 1458 }.get(status, Fore.WHITE)
1459 1459
1460 def fetch_cl_status(b, auth_config=None): 1460 def fetch_cl_status(branch, auth_config=None):
1461 """Fetches information for an issue and returns (branch, issue, color).""" 1461 """Fetches information for an issue and returns (branch, issue, status)."""
1462 c = Changelist(branchref=b, auth_config=auth_config) 1462 cl = Changelist(branchref=branch, auth_config=auth_config)
1463 i = c.GetIssueURL() 1463 url = cl.GetIssueURL()
1464 status = c.GetStatus() 1464 status = cl.GetStatus()
1465 color = color_for_status(status)
1466 1465
1467 if i and (not status or status == 'error'): 1466 if url and (not status or status == 'error'):
1468 # The issue probably doesn't exist anymore. 1467 # The issue probably doesn't exist anymore.
1469 i += ' (broken)' 1468 url += ' (broken)'
1470 1469
1471 return (b, i, color) 1470 return (branch, url, status)
1472 1471
1473 def get_cl_statuses( 1472 def get_cl_statuses(
1474 branches, fine_grained, max_processes=None, auth_config=None): 1473 branches, fine_grained, max_processes=None, auth_config=None):
1475 """Returns a blocking iterable of (branch, issue, color) for given branches. 1474 """Returns a blocking iterable of (branch, issue, color) for given branches.
1476 1475
1477 If fine_grained is true, this will fetch CL statuses from the server. 1476 If fine_grained is true, this will fetch CL statuses from the server.
1478 Otherwise, simply indicate if there's a matching url for the given branches. 1477 Otherwise, simply indicate if there's a matching url for the given branches.
1479 1478
1480 If max_processes is specified, it is used as the maximum number of processes 1479 If max_processes is specified, it is used as the maximum number of processes
1481 to spawn to fetch CL status from the server. Otherwise 1 process per branch is 1480 to spawn to fetch CL status from the server. Otherwise 1 process per branch is
(...skipping 12 matching lines...) Expand all
1494 branches_to_fetch = branches[1:] 1493 branches_to_fetch = branches[1:]
1495 pool = ThreadPool( 1494 pool = ThreadPool(
1496 min(max_processes, len(branches_to_fetch)) 1495 min(max_processes, len(branches_to_fetch))
1497 if max_processes is not None 1496 if max_processes is not None
1498 else len(branches_to_fetch)) 1497 else len(branches_to_fetch))
1499 for x in pool.imap_unordered(fetch, branches_to_fetch): 1498 for x in pool.imap_unordered(fetch, branches_to_fetch):
1500 yield x 1499 yield x
1501 else: 1500 else:
1502 # Do not use GetApprovingReviewers(), since it requires an HTTP request. 1501 # Do not use GetApprovingReviewers(), since it requires an HTTP request.
1503 for b in branches: 1502 for b in branches:
1504 c = Changelist(branchref=b, auth_config=auth_config) 1503 cl = Changelist(branchref=b, auth_config=auth_config)
1505 url = c.GetIssueURL() 1504 url = cl.GetIssueURL()
1506 yield (b, url, Fore.BLUE if url else Fore.WHITE) 1505 yield (b, url, 'waiting' if url else 'error')
1507 1506
1508 def CMDstatus(parser, args): 1507 def CMDstatus(parser, args):
1509 """Show status of changelists. 1508 """Show status of changelists.
1510 1509
1511 Colors are used to tell the state of the CL unless --fast is used: 1510 Colors are used to tell the state of the CL unless --fast is used:
1512 - Red not sent for review or broken 1511 - Red not sent for review or broken
1513 - Blue waiting for review 1512 - Blue waiting for review
1514 - Yellow waiting for you to reply to review 1513 - Yellow waiting for you to reply to review
1515 - Green LGTM'ed 1514 - Green LGTM'ed
1516 - Magenta in the commit queue 1515 - Magenta in the commit queue
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 print 'Branches associated with reviews:' 1562 print 'Branches associated with reviews:'
1564 output = get_cl_statuses(branches, 1563 output = get_cl_statuses(branches,
1565 fine_grained=not options.fast, 1564 fine_grained=not options.fast,
1566 max_processes=options.maxjobs, 1565 max_processes=options.maxjobs,
1567 auth_config=auth_config) 1566 auth_config=auth_config)
1568 1567
1569 branch_statuses = {} 1568 branch_statuses = {}
1570 alignment = max(5, max(len(ShortBranchName(b)) for b in branches)) 1569 alignment = max(5, max(len(ShortBranchName(b)) for b in branches))
1571 for branch in sorted(branches): 1570 for branch in sorted(branches):
1572 while branch not in branch_statuses: 1571 while branch not in branch_statuses:
1573 b, i, color = output.next() 1572 b, i, status = output.next()
1574 branch_statuses[b] = (i, color) 1573 branch_statuses[b] = (i, status)
1575 issue, color = branch_statuses.pop(branch) 1574 issue_url, status = branch_statuses.pop(branch)
1575 color = color_for_status(status)
1576 reset = Fore.RESET 1576 reset = Fore.RESET
1577 if not sys.stdout.isatty(): 1577 if not sys.stdout.isatty():
1578 color = '' 1578 color = ''
1579 reset = '' 1579 reset = ''
1580 print ' %*s : %s%s%s' % ( 1580 status_str = '(%s)' % status if status else ''
1581 alignment, ShortBranchName(branch), color, issue, reset) 1581 print ' %*s : %s%s %s%s' % (
1582 alignment, ShortBranchName(branch), color, issue_url, status_str,
1583 reset)
1582 1584
1583 cl = Changelist(auth_config=auth_config) 1585 cl = Changelist(auth_config=auth_config)
1584 print 1586 print
1585 print 'Current branch:', 1587 print 'Current branch:',
1586 if not cl.GetIssue(): 1588 if not cl.GetIssue():
1587 print 'no issue assigned.' 1589 print 'no issue assigned.'
1588 return 0 1590 return 0
1589 print cl.GetBranch() 1591 print cl.GetBranch()
1590 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) 1592 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL())
1591 if not options.fast: 1593 if not options.fast:
(...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after
3372 if __name__ == '__main__': 3374 if __name__ == '__main__':
3373 # These affect sys.stdout so do it outside of main() to simplify mocks in 3375 # These affect sys.stdout so do it outside of main() to simplify mocks in
3374 # unit testing. 3376 # unit testing.
3375 fix_encoding.fix_encoding() 3377 fix_encoding.fix_encoding()
3376 colorama.init() 3378 colorama.init()
3377 try: 3379 try:
3378 sys.exit(main(sys.argv[1:])) 3380 sys.exit(main(sys.argv[1:]))
3379 except KeyboardInterrupt: 3381 except KeyboardInterrupt:
3380 sys.stderr.write('interrupted\n') 3382 sys.stderr.write('interrupted\n')
3381 sys.exit(1) 3383 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698