def GetTargetRef(remote, remote_branch, target_branch, pending_prefix):
    'Computes the remote branch ref to use for the CL.\n\n  Args:\n    remote (str): The git remote for the CL.\n    remote_branch (str): The git remote branch for the CL.\n    target_branch (str): The target branch specified by the user.\n    pending_prefix (str): The pending prefix from the settings.\n  '
    if (not (remote and remote_branch)):
        return None
    if target_branch:
        if ('/' not in target_branch):
            remote_branch = ('refs/remotes/%s/%s' % (remote, target_branch))
        else:
            prefix_replacements = (('^((refs/)?remotes/)?branch-heads/', 'refs/remotes/branch-heads/'), (('^((refs/)?remotes/)?%s/' % remote), ('refs/remotes/%s/' % remote)), ('^(refs/)?heads/', ('refs/remotes/%s/' % remote)))
            match = None
            for (regex, replacement) in prefix_replacements:
                match = re.search(regex, target_branch)
                if match:
                    remote_branch = target_branch.replace(match.group(0), replacement)
                    break
            if (not match):
                remote_branch = target_branch
    elif (remote_branch in REFS_THAT_ALIAS_TO_OTHER_REFS):
        remote_branch = REFS_THAT_ALIAS_TO_OTHER_REFS[remote_branch]
    if remote_branch.startswith(('refs/remotes/%s/refs/' % remote)):
        remote_branch = remote_branch.replace(('refs/remotes/%s/' % remote), '')
    elif remote_branch.startswith(('refs/remotes/%s/' % remote)):
        remote_branch = remote_branch.replace(('refs/remotes/%s/' % remote), 'refs/heads/')
    elif remote_branch.startswith('refs/remotes/branch-heads'):
        remote_branch = remote_branch.replace('refs/remotes/', 'refs/')
    if pending_prefix:
        remote_branch = remote_branch.replace('refs/', pending_prefix)
    return remote_branch
Computes the remote branch ref to use for the CL.

Args:
  remote (str): The git remote for the CL.
  remote_branch (str): The git remote branch for the CL.
  target_branch (str): The target branch specified by the user.
  pending_prefix (str): The pending prefix from the settings.
def GetTargetRef(remote, remote_branch, target_branch, pending_prefix):
    'Computes the remote branch ref to use for the CL.\n\n  Args:\n    remote (str): The git remote for the CL.\n    remote_branch (str): The git remote branch for the CL.\n    target_branch (str): The target branch specified by the user.\n    pending_prefix (str): The pending prefix from the settings.\n  '
    if (not (remote and remote_branch)):
        return None
    if target_branch:
        if ('/' not in target_branch):
            remote_branch = ('refs/remotes/%s/%s' % (remote, target_branch))
        else:
            prefix_replacements = (('^((refs/)?remotes/)?branch-heads/', 'refs/remotes/branch-heads/'), (('^((refs/)?remotes/)?%s/' % remote), ('refs/remotes/%s/' % remote)), ('^(refs/)?heads/', ('refs/remotes/%s/' % remote)))
            match = None
            for (regex, replacement) in prefix_replacements:
                match = re.search(regex, target_branch)
                if match:
                    remote_branch = target_branch.replace(match.group(0), replacement)
                    break
            if (not match):
                remote_branch = target_branch
    elif (remote_branch in REFS_THAT_ALIAS_TO_OTHER_REFS):
        remote_branch = REFS_THAT_ALIAS_TO_OTHER_REFS[remote_branch]
    if remote_branch.startswith(('refs/remotes/%s/refs/' % remote)):
        remote_branch = remote_branch.replace(('refs/remotes/%s/' % remote), )
    elif remote_branch.startswith(('refs/remotes/%s/' % remote)):
        remote_branch = remote_branch.replace(('refs/remotes/%s/' % remote), 'refs/heads/')
    elif remote_branch.startswith('refs/remotes/branch-heads'):
        remote_branch = remote_branch.replace('refs/remotes/', 'refs/')
    if pending_prefix:
        remote_branch = remote_branch.replace('refs/', pending_prefix)
    return remote_branch