@subcommand.usage('<codereview url or issue id>')
def CMDcheckout(parser, args):
    'Checks out a branch associated with a given Rietveld or Gerrit issue.'
    (_, args) = parser.parse_args(args)
    if (len(args) != 1):
        parser.print_help()
        return 1
    issue_arg = ParseIssueNumberArgument(args[0])
    if (not issue_arg.valid):
        parser.print_help()
        return 1
    target_issue = str(issue_arg.issue)

    def find_issues(issueprefix):
        output = RunGit(['config', '--local', '--get-regexp', ('branch\\..*\\.%s' % issueprefix)], error_ok=True)
        for (key, issue) in [x.split() for x in output.splitlines()]:
            if (issue == target_issue):
                (yield re.sub(('branch\\.(.*)\\.%s' % issueprefix), '\\1', key))
    branches = []
    for cls in _CODEREVIEW_IMPLEMENTATIONS.values():
        branches.extend(find_issues(cls.IssueSettingSuffix()))
    if (len(branches) == 0):
        print(('No branch found for issue %s.' % target_issue))
        return 1
    if (len(branches) == 1):
        RunGit(['checkout', branches[0]])
    else:
        print(('Multiple branches match issue %s:' % target_issue))
        for i in range(len(branches)):
            print(('%d: %s' % (i, branches[i])))
        which = raw_input('Choose by index: ')
        try:
            RunGit(['checkout', branches[int(which)]])
        except (IndexError, ValueError):
            print('Invalid selection, not checking out any branch.')
            return 1
    return 0
Checks out a branch associated with a given Rietveld or Gerrit issue.
@subcommand.usage('<codereview url or issue id>')
def CMDcheckout(parser, args):
    
    (_, args) = parser.parse_args(args)
    if (len(args) != 1):
        parser.print_help()
        return 1
    issue_arg = ParseIssueNumberArgument(args[0])
    if (not issue_arg.valid):
        parser.print_help()
        return 1
    target_issue = str(issue_arg.issue)

    def find_issues(issueprefix):
        output = RunGit(['config', '--local', '--get-regexp', ('branch\\..*\\.%s' % issueprefix)], error_ok=True)
        for (key, issue) in [x.split() for x in output.splitlines()]:
            if (issue == target_issue):
                (yield re.sub(('branch\\.(.*)\\.%s' % issueprefix), '\\1', key))
    branches = []
    for cls in _CODEREVIEW_IMPLEMENTATIONS.values():
        branches.extend(find_issues(cls.IssueSettingSuffix()))
    if (len(branches) == 0):
        print(('No branch found for issue %s.' % target_issue))
        return 1
    if (len(branches) == 1):
        RunGit(['checkout', branches[0]])
    else:
        print(('Multiple branches match issue %s:' % target_issue))
        for i in range(len(branches)):
            print(('%d: %s' % (i, branches[i])))
        which = raw_input('Choose by index: ')
        try:
            RunGit(['checkout', branches[int(which)]])
        except (IndexError, ValueError):
            print('Invalid selection, not checking out any branch.')
            return 1
    return 0