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

Side by Side Diff: git_cl.py

Issue 969263002: git_cl: Add reverse issue lookup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: 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 | 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if branch: 152 if branch:
153 git_key = 'branch.%s.%s' % (branch, key) 153 git_key = 'branch.%s.%s' % (branch, key)
154 (_, stdout) = RunGitWithCode(['config', '--int', '--get', git_key]) 154 (_, stdout) = RunGitWithCode(['config', '--int', '--get', git_key])
155 try: 155 try:
156 return int(stdout.strip()) 156 return int(stdout.strip())
157 except ValueError: 157 except ValueError:
158 pass 158 pass
159 return default 159 return default
160 160
161 161
162 def git_list_branches():
163 return RunGit(['for-each-ref', 'refs/heads',
164 '--format=%(refname:short)']).splitlines()
iannucci 2015/03/03 02:42:31 this seems pretty one-off. Could we make it not a
dnj 2015/03/03 02:43:20 Sure - the problem with following suit is when the
165
166
162 def add_git_similarity(parser): 167 def add_git_similarity(parser):
163 parser.add_option( 168 parser.add_option(
164 '--similarity', metavar='SIM', type='int', action='store', 169 '--similarity', metavar='SIM', type='int', action='store',
165 help='Sets the percentage that a pair of files need to match in order to' 170 help='Sets the percentage that a pair of files need to match in order to'
166 ' be considered copies (default 50)') 171 ' be considered copies (default 50)')
167 parser.add_option( 172 parser.add_option(
168 '--find-copies', action='store_true', 173 '--find-copies', action='store_true',
169 help='Allows git to look for copies.') 174 help='Allows git to look for copies.')
170 parser.add_option( 175 parser.add_option(
171 '--no-find-copies', action='store_false', dest='find_copies', 176 '--no-find-copies', action='store_false', dest='find_copies',
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 lines = CMDstatus.__doc__.splitlines() 1471 lines = CMDstatus.__doc__.splitlines()
1467 CMDstatus.__doc__ = '\n'.join(colorize_line(l) for l in lines) 1472 CMDstatus.__doc__ = '\n'.join(colorize_line(l) for l in lines)
1468 1473
1469 1474
1470 @subcommand.usage('[issue_number]') 1475 @subcommand.usage('[issue_number]')
1471 def CMDissue(parser, args): 1476 def CMDissue(parser, args):
1472 """Sets or displays the current code review issue number. 1477 """Sets or displays the current code review issue number.
1473 1478
1474 Pass issue number 0 to clear the current issue. 1479 Pass issue number 0 to clear the current issue.
1475 """ 1480 """
1476 _, args = parser.parse_args(args) 1481 parser.add_option('-r', '--reverse', action='store_true',
1482 help='Lookup the branch(es) for the specified issues. If '
1483 'no issues are specified, all branches with mapped '
1484 'issues will be listed.')
1485 options, args = parser.parse_args(args)
1477 1486
1478 cl = Changelist() 1487 if options.reverse:
1479 if len(args) > 0: 1488 # Reverse issue lookup.
1480 try: 1489 issue_branch_map = {}
1481 issue = int(args[0]) 1490 for branch in git_list_branches():
1482 except ValueError: 1491 cl = Changelist(branchref=branch)
1483 DieWithError('Pass a number to set the issue or none to list it.\n' 1492 issue_branch_map.setdefault(cl.GetIssue(), []).append(branch)
1484 'Maybe you want to run git cl status?') 1493 if not args:
1485 cl.SetIssue(issue) 1494 args = sorted(issue_branch_map.iterkeys())
1486 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) 1495 for issue in args:
1496 if not issue:
1497 continue
1498 print 'Branch for issue number %s: %s' % (
1499 issue, ', '.join(issue_branch_map.get(int(issue)) or ('None',)))
1500 else:
1501 cl = Changelist()
1502 if len(args) > 0:
1503 try:
1504 issue = int(args[0])
1505 except ValueError:
1506 DieWithError('Pass a number to set the issue or none to list it.\n'
1507 'Maybe you want to run git cl status?')
1508 cl.SetIssue(issue)
1509 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL())
1487 return 0 1510 return 0
1488 1511
1489 1512
1490 def CMDcomments(parser, args): 1513 def CMDcomments(parser, args):
1491 """Shows or posts review comments for any changelist.""" 1514 """Shows or posts review comments for any changelist."""
1492 parser.add_option('-a', '--add-comment', dest='comment', 1515 parser.add_option('-a', '--add-comment', dest='comment',
1493 help='comment to add to an issue') 1516 help='comment to add to an issue')
1494 parser.add_option('-i', dest='issue', 1517 parser.add_option('-i', dest='issue',
1495 help="review issue id (defaults to current issue)") 1518 help="review issue id (defaults to current issue)")
1496 options, args = parser.parse_args(args) 1519 options, args = parser.parse_args(args)
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after
3094 if __name__ == '__main__': 3117 if __name__ == '__main__':
3095 # These affect sys.stdout so do it outside of main() to simplify mocks in 3118 # These affect sys.stdout so do it outside of main() to simplify mocks in
3096 # unit testing. 3119 # unit testing.
3097 fix_encoding.fix_encoding() 3120 fix_encoding.fix_encoding()
3098 colorama.init() 3121 colorama.init()
3099 try: 3122 try:
3100 sys.exit(main(sys.argv[1:])) 3123 sys.exit(main(sys.argv[1:]))
3101 except KeyboardInterrupt: 3124 except KeyboardInterrupt:
3102 sys.stderr.write('interrupted\n') 3125 sys.stderr.write('interrupted\n')
3103 sys.exit(1) 3126 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