Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index bcd4a6252b018978cc860b3ebebf75dd6f197d54..ac7495dd9e479a2d3ecb80d121bb83f1af354743 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -159,6 +159,11 @@ def git_get_branch_default(key, default): |
| return default |
| +def git_list_branches(): |
| + return RunGit(['for-each-ref', 'refs/heads', |
| + '--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
|
| + |
| + |
| def add_git_similarity(parser): |
| parser.add_option( |
| '--similarity', metavar='SIM', type='int', action='store', |
| @@ -1473,17 +1478,35 @@ def CMDissue(parser, args): |
| 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 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()) |
| + if options.reverse: |
| + # Reverse issue lookup. |
| + issue_branch_map = {} |
| + for branch in git_list_branches(): |
| + cl = Changelist(branchref=branch) |
| + 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 |