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 import logging | 10 import logging |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 parser.add_option('--field', | 792 parser.add_option('--field', |
793 help='print only specific field (desc|id|patch|url)') | 793 help='print only specific field (desc|id|patch|url)') |
794 (options, args) = parser.parse_args(args) | 794 (options, args) = parser.parse_args(args) |
795 | 795 |
796 # TODO: maybe make show_branches a flag if necessary. | 796 # TODO: maybe make show_branches a flag if necessary. |
797 show_branches = not options.field | 797 show_branches = not options.field |
798 | 798 |
799 if show_branches: | 799 if show_branches: |
800 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) | 800 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) |
801 if branches: | 801 if branches: |
802 print 'Branches associated with reviews:' | 802 alignment = 5 |
M-A Ruel
2012/04/02 19:56:25
You can code it even shorter with:
print 'Branche
| |
803 branch_info = [] | |
803 for branch in sorted(branches.splitlines()): | 804 for branch in sorted(branches.splitlines()): |
804 cl = Changelist(branchref=branch) | 805 cl = Changelist(branchref=branch) |
805 print " %10s: %s" % (cl.GetBranch(), cl.GetIssue()) | 806 alignment = max(alignment, len(cl.GetBranch())) |
807 branch_info.append([cl.GetBranch(), cl.GetIssue()]) | |
808 | |
809 print 'Branches associated with reviews:' | |
810 for info in branch_info: | |
811 print " %*s: %s" % (alignment, info[0], info[1]) | |
806 | 812 |
807 cl = Changelist() | 813 cl = Changelist() |
808 if options.field: | 814 if options.field: |
809 if options.field.startswith('desc'): | 815 if options.field.startswith('desc'): |
810 print cl.GetDescription() | 816 print cl.GetDescription() |
811 elif options.field == 'id': | 817 elif options.field == 'id': |
812 issueid = cl.GetIssue() | 818 issueid = cl.GetIssue() |
813 if issueid: | 819 if issueid: |
814 print issueid | 820 print issueid |
815 elif options.field == 'patch': | 821 elif options.field == 'patch': |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1519 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1525 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1520 | 1526 |
1521 # Not a known command. Default to help. | 1527 # Not a known command. Default to help. |
1522 GenUsage(parser, 'help') | 1528 GenUsage(parser, 'help') |
1523 return CMDhelp(parser, argv) | 1529 return CMDhelp(parser, argv) |
1524 | 1530 |
1525 | 1531 |
1526 if __name__ == '__main__': | 1532 if __name__ == '__main__': |
1527 fix_encoding.fix_encoding() | 1533 fix_encoding.fix_encoding() |
1528 sys.exit(main(sys.argv[1:])) | 1534 sys.exit(main(sys.argv[1:])) |
OLD | NEW |