Commit 406c4404 authored by dnj@chromium.org's avatar dnj@chromium.org

git_cl: Add reverse issue lookup.

Add the ability to lookup the branch(es) corresponding to a specific
issue. This helps keep track of issues when switching between multiple
branches.

BUG=None
TEST=None

Review URL: https://codereview.chromium.org/969263002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@294307 0039d316-1c4b-4281-b951-d872f2087c98
parent c68112d9
...@@ -1477,17 +1477,38 @@ def CMDissue(parser, args): ...@@ -1477,17 +1477,38 @@ def CMDissue(parser, args):
Pass issue number 0 to clear the current issue. Pass issue number 0 to clear the current issue.
""" """
_, args = parser.parse_args(args) parser.add_option('-r', '--reverse', action='store_true',
help='Lookup the branch(es) for the specified issues. If '
'no issues are specified, all branches with mapped '
'issues will be listed.')
options, args = parser.parse_args(args)
cl = Changelist() if options.reverse:
if len(args) > 0: branches = RunGit(['for-each-ref', 'refs/heads',
try: '--format=%(refname:short)']).splitlines()
issue = int(args[0])
except ValueError: # Reverse issue lookup.
DieWithError('Pass a number to set the issue or none to list it.\n' issue_branch_map = {}
'Maybe you want to run git cl status?') for branch in branches:
cl.SetIssue(issue) cl = Changelist(branchref=branch)
print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) issue_branch_map.setdefault(cl.GetIssue(), []).append(branch)
if not args:
args = sorted(issue_branch_map.iterkeys())
for issue in args:
if not issue:
continue
print 'Branch for issue number %s: %s' % (
issue, ', '.join(issue_branch_map.get(int(issue)) or ('None',)))
else:
cl = Changelist()
if len(args) > 0:
try:
issue = int(args[0])
except ValueError:
DieWithError('Pass a number to set the issue or none to list it.\n'
'Maybe you want to run git cl status?')
cl.SetIssue(issue)
print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL())
return 0 return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment