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

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: Created 5 years, 10 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 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 return { 1321 return {
1322 'unsent': Fore.RED, 1322 'unsent': Fore.RED,
1323 'waiting': Fore.BLUE, 1323 'waiting': Fore.BLUE,
1324 'reply': Fore.YELLOW, 1324 'reply': Fore.YELLOW,
1325 'lgtm': Fore.GREEN, 1325 'lgtm': Fore.GREEN,
1326 'commit': Fore.MAGENTA, 1326 'commit': Fore.MAGENTA,
1327 'closed': Fore.CYAN, 1327 'closed': Fore.CYAN,
1328 'error': Fore.WHITE, 1328 'error': Fore.WHITE,
1329 }.get(status, Fore.WHITE) 1329 }.get(status, Fore.WHITE)
1330 1330
1331 def get_cl_statuses(branches, fast=False):
1332 """Returns a blocking Queue of (branch, issue, color) for provided branches.
1333
1334 If fast is false, this will spawn len(branches) number of threads and fetch
1335 the remote cl statuses.
1336 """
1337 # Adhoc thread pool to request data concurrently.
1338 output = Queue.Queue()
1339
1340 # Silence upload.py otherwise it becomes unweldly.
1341 upload.verbosity = 0
1342
1343 if not fast:
1344 def fetch(b):
1345 """Fetches information for an issue and returns (branch, issue, color)."""
1346 c = Changelist(branchref=b)
1347 i = c.GetIssueURL()
1348 status = c.GetStatus()
1349 color = color_for_status(status)
1350
1351 if i and (not status or status == 'error'):
1352 # The issue probably doesn't exist anymore.
1353 i += ' (broken)'
1354
1355 output.put((b, i, color))
1356
1357 # Process one branch synchronously to work through authentication, then
1358 # spawn threads to process all the other branches in parallel.
1359 if branches:
1360 fetch(branches[0])
1361 threads = [
1362 threading.Thread(target=fetch, args=(b,)) for b in branches[1:]]
1363 for t in threads:
1364 t.daemon = True
1365 t.start()
1366 else:
1367 # Do not use GetApprovingReviewers(), since it requires an HTTP request.
1368 for b in branches:
1369 c = Changelist(branchref=b)
1370 url = c.GetIssueURL()
1371 output.put((b, url, Fore.BLUE if url else Fore.WHITE))
1372
1373 return output
1331 1374
1332 def CMDstatus(parser, args): 1375 def CMDstatus(parser, args):
1333 """Show status of changelists. 1376 """Show status of changelists.
1334 1377
1335 Colors are used to tell the state of the CL unless --fast is used: 1378 Colors are used to tell the state of the CL unless --fast is used:
1336 - Red not sent for review or broken 1379 - Red not sent for review or broken
1337 - Blue waiting for review 1380 - Blue waiting for review
1338 - Yellow waiting for you to reply to review 1381 - Yellow waiting for you to reply to review
1339 - Green LGTM'ed 1382 - Green LGTM'ed
1340 - Magenta in the commit queue 1383 - Magenta in the commit queue
(...skipping 29 matching lines...) Expand all
1370 1413
1371 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) 1414 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads'])
1372 if not branches: 1415 if not branches:
1373 print('No local branch found.') 1416 print('No local branch found.')
1374 return 0 1417 return 0
1375 1418
1376 changes = (Changelist(branchref=b) for b in branches.splitlines()) 1419 changes = (Changelist(branchref=b) for b in branches.splitlines())
1377 branches = [c.GetBranch() for c in changes] 1420 branches = [c.GetBranch() for c in changes]
1378 alignment = max(5, max(len(b) for b in branches)) 1421 alignment = max(5, max(len(b) for b in branches))
1379 print 'Branches associated with reviews:' 1422 print 'Branches associated with reviews:'
1380 # Adhoc thread pool to request data concurrently. 1423 output = get_cl_statuses(branches, options.fast)
1381 output = Queue.Queue()
1382
1383 # Silence upload.py otherwise it becomes unweldly.
1384 upload.verbosity = 0
1385
1386 if not options.fast:
1387 def fetch(b):
1388 """Fetches information for an issue and returns (branch, issue, color)."""
1389 c = Changelist(branchref=b)
1390 i = c.GetIssueURL()
1391 status = c.GetStatus()
1392 color = color_for_status(status)
1393
1394 if i and (not status or status == 'error'):
1395 # The issue probably doesn't exist anymore.
1396 i += ' (broken)'
1397
1398 output.put((b, i, color))
1399
1400 # Process one branch synchronously to work through authentication, then
1401 # spawn threads to process all the other branches in parallel.
1402 if branches:
1403 fetch(branches[0])
1404 threads = [
1405 threading.Thread(target=fetch, args=(b,)) for b in branches[1:]]
1406 for t in threads:
1407 t.daemon = True
1408 t.start()
1409 else:
1410 # Do not use GetApprovingReviewers(), since it requires an HTTP request.
1411 for b in branches:
1412 c = Changelist(branchref=b)
1413 url = c.GetIssueURL()
1414 output.put((b, url, Fore.BLUE if url else Fore.WHITE))
1415 1424
1416 tmp = {} 1425 tmp = {}
1417 alignment = max(5, max(len(ShortBranchName(b)) for b in branches)) 1426 alignment = max(5, max(len(ShortBranchName(b)) for b in branches))
1418 for branch in sorted(branches): 1427 for branch in sorted(branches):
1419 while branch not in tmp: 1428 while branch not in tmp:
1420 b, i, color = output.get() 1429 b, i, color = output.get()
1421 tmp[b] = (i, color) 1430 tmp[b] = (i, color)
1422 issue, color = tmp.pop(branch) 1431 issue, color = tmp.pop(branch)
1423 reset = Fore.RESET 1432 reset = Fore.RESET
1424 if not sys.stdout.isatty(): 1433 if not sys.stdout.isatty():
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after
3044 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 3053 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
3045 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 3054 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
3046 3055
3047 3056
3048 if __name__ == '__main__': 3057 if __name__ == '__main__':
3049 # These affect sys.stdout so do it outside of main() to simplify mocks in 3058 # These affect sys.stdout so do it outside of main() to simplify mocks in
3050 # unit testing. 3059 # unit testing.
3051 fix_encoding.fix_encoding() 3060 fix_encoding.fix_encoding()
3052 colorama.init() 3061 colorama.init()
3053 sys.exit(main(sys.argv[1:])) 3062 sys.exit(main(sys.argv[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