OLD | NEW |
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 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 lines = CMDstatus.__doc__.splitlines() | 1466 lines = CMDstatus.__doc__.splitlines() |
1467 CMDstatus.__doc__ = '\n'.join(colorize_line(l) for l in lines) | 1467 CMDstatus.__doc__ = '\n'.join(colorize_line(l) for l in lines) |
1468 | 1468 |
1469 | 1469 |
1470 @subcommand.usage('[issue_number]') | 1470 @subcommand.usage('[issue_number]') |
1471 def CMDissue(parser, args): | 1471 def CMDissue(parser, args): |
1472 """Sets or displays the current code review issue number. | 1472 """Sets or displays the current code review issue number. |
1473 | 1473 |
1474 Pass issue number 0 to clear the current issue. | 1474 Pass issue number 0 to clear the current issue. |
1475 """ | 1475 """ |
1476 _, args = parser.parse_args(args) | 1476 parser.add_option('-r', '--reverse', action='store_true', |
| 1477 help='Lookup the branch(es) for the specified issues. If ' |
| 1478 'no issues are specified, all branches with mapped ' |
| 1479 'issues will be listed.') |
| 1480 options, args = parser.parse_args(args) |
1477 | 1481 |
1478 cl = Changelist() | 1482 if options.reverse: |
1479 if len(args) > 0: | 1483 branches = RunGit(['for-each-ref', 'refs/heads', |
1480 try: | 1484 '--format=%(refname:short)']).splitlines() |
1481 issue = int(args[0]) | 1485 |
1482 except ValueError: | 1486 # Reverse issue lookup. |
1483 DieWithError('Pass a number to set the issue or none to list it.\n' | 1487 issue_branch_map = {} |
1484 'Maybe you want to run git cl status?') | 1488 for branch in branches: |
1485 cl.SetIssue(issue) | 1489 cl = Changelist(branchref=branch) |
1486 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) | 1490 issue_branch_map.setdefault(cl.GetIssue(), []).append(branch) |
| 1491 if not args: |
| 1492 args = sorted(issue_branch_map.iterkeys()) |
| 1493 for issue in args: |
| 1494 if not issue: |
| 1495 continue |
| 1496 print 'Branch for issue number %s: %s' % ( |
| 1497 issue, ', '.join(issue_branch_map.get(int(issue)) or ('None',))) |
| 1498 else: |
| 1499 cl = Changelist() |
| 1500 if len(args) > 0: |
| 1501 try: |
| 1502 issue = int(args[0]) |
| 1503 except ValueError: |
| 1504 DieWithError('Pass a number to set the issue or none to list it.\n' |
| 1505 'Maybe you want to run git cl status?') |
| 1506 cl.SetIssue(issue) |
| 1507 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) |
1487 return 0 | 1508 return 0 |
1488 | 1509 |
1489 | 1510 |
1490 def CMDcomments(parser, args): | 1511 def CMDcomments(parser, args): |
1491 """Shows or posts review comments for any changelist.""" | 1512 """Shows or posts review comments for any changelist.""" |
1492 parser.add_option('-a', '--add-comment', dest='comment', | 1513 parser.add_option('-a', '--add-comment', dest='comment', |
1493 help='comment to add to an issue') | 1514 help='comment to add to an issue') |
1494 parser.add_option('-i', dest='issue', | 1515 parser.add_option('-i', dest='issue', |
1495 help="review issue id (defaults to current issue)") | 1516 help="review issue id (defaults to current issue)") |
1496 options, args = parser.parse_args(args) | 1517 options, args = parser.parse_args(args) |
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3094 if __name__ == '__main__': | 3115 if __name__ == '__main__': |
3095 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3116 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3096 # unit testing. | 3117 # unit testing. |
3097 fix_encoding.fix_encoding() | 3118 fix_encoding.fix_encoding() |
3098 colorama.init() | 3119 colorama.init() |
3099 try: | 3120 try: |
3100 sys.exit(main(sys.argv[1:])) | 3121 sys.exit(main(sys.argv[1:])) |
3101 except KeyboardInterrupt: | 3122 except KeyboardInterrupt: |
3102 sys.stderr.write('interrupted\n') | 3123 sys.stderr.write('interrupted\n') |
3103 sys.exit(1) | 3124 sys.exit(1) |
OLD | NEW |