def CMDUploadChange(self, options, args, change):
    'Upload the current branch to Gerrit.'
    if (options.squash and options.no_squash):
        DieWithError('Can only use one of --squash or --no-squash')
    if ((not options.squash) and (not options.no_squash)):
        options.squash = settings.GetSquashGerritUploads()
    elif options.no_squash:
        options.squash = False
    gerrit_remote = 'origin'
    (remote, remote_branch) = self.GetRemoteBranch()
    branch = GetTargetRef(remote, remote_branch, options.target_branch, pending_prefix='')
    if options.squash:
        self._GerritCommitMsgHookCheck(offer_removal=(not options.force))
        if (not self.GetIssue()):
            message = RunGitSilent(['show', '--format=%B', '-s', ('refs/heads/git_cl_uploads/%s' % self.GetBranch())])
            if message:
                change_ids = git_footers.get_footer_change_id(message.strip())
                if (change_ids and (len(change_ids) == 1)):
                    details = self._GetChangeDetail(issue=change_ids[0])
                    if details:
                        print(('WARNING: found old upload in branch git_cl_uploads/%s corresponding to issue %s' % (self.GetBranch(), details['_number'])))
                        self.SetIssue(details['_number'])
                if (not self.GetIssue()):
                    DieWithError(('\nFound old upload in branch git_cl_uploads/%s, but failed to find corresponding Gerrit issue.\nIf you know the issue number, set it manually first:\n    git cl issue 123456\nIf you intended to upload this CL as new issue, just delete or rename the old upload branch:\n    git rename-branch git_cl_uploads/%s old_upload-%s\nAfter that, please run git cl upload again.' % tuple(([self.GetBranch()] * 3))))
        if self.GetIssue():
            message = self.GetDescription()
            if (not message):
                DieWithError(('failed to fetch description from current Gerrit issue %d\n%s' % (self.GetIssue(), self.GetIssueURL())))
            change_id = self._GetChangeDetail()['change_id']
            while True:
                footer_change_ids = git_footers.get_footer_change_id(message)
                if (footer_change_ids == [change_id]):
                    break
                if (not footer_change_ids):
                    message = git_footers.add_footer_change_id(message, change_id)
                    print('WARNING: appended missing Change-Id to issue description')
                    continue
                message = ('%s\n\nChange-Id: %s' % (message, change_id))
                print(('WARNING: issue %s has Change-Id footer(s):\n  %s\nbut issue has Change-Id %s, according to Gerrit.\nPlease, check the proposed correction to the description, and edit it if necessary but keep the "Change-Id: %s" footer\n' % (self.GetIssue(), '\n  '.join(footer_change_ids), change_id, change_id)))
                ask_for_data('Press enter to edit now, Ctrl+C to abort')
                if (not options.force):
                    change_desc = ChangeDescription(message)
                    change_desc.prompt()
                    message = change_desc.description
                    if (not message):
                        DieWithError('Description is empty. Aborting...')
            assert ([change_id] == git_footers.get_footer_change_id(message))
            change_desc = ChangeDescription(message)
        else:
            change_desc = ChangeDescription((options.message or CreateDescriptionFromLog(args)))
            if (not options.force):
                change_desc.prompt()
            if (not change_desc.description):
                DieWithError('Description is empty. Aborting...')
            message = change_desc.description
            change_ids = git_footers.get_footer_change_id(message)
            if (len(change_ids) > 1):
                DieWithError('too many Change-Id footers, at most 1 allowed.')
            if (not change_ids):
                message = git_footers.add_footer_change_id(message, GenerateGerritChangeId(message))
                change_desc.set_description(message)
                change_ids = git_footers.get_footer_change_id(message)
                assert (len(change_ids) == 1)
            change_id = change_ids[0]
        (remote, upstream_branch) = self.FetchUpstreamTuple(self.GetBranch())
        if (remote is '.'):
            upstream_branch_name = scm.GIT.ShortBranchName(upstream_branch)
            parent = RunGit(['config', ('branch.%s.gerritsquashhash' % upstream_branch_name)], error_ok=True).strip()
            if ((not parent) or (RunGitSilent(['rev-parse', (upstream_branch + ':')]) != RunGitSilent(['rev-parse', (parent + ':')]))):
                DieWithError(("Upload upstream branch %s first.\nNote: maybe you've uploaded it with --no-squash or with an old version of depot_tools. If so, then re-upload it with:\n    git cl upload --squash\n" % upstream_branch_name))
        else:
            parent = self.GetCommonAncestorWithUpstream()
        tree = RunGit(['rev-parse', 'HEAD:']).strip()
        ref_to_push = RunGit(['commit-tree', tree, '-p', parent, '-m', message]).strip()
    else:
        change_desc = ChangeDescription((options.message or CreateDescriptionFromLog(args)))
        if (not change_desc.description):
            DieWithError('Description is empty. Aborting...')
        if (not git_footers.get_footer_change_id(change_desc.description)):
            DownloadGerritHook(False)
            change_desc.set_description(self._AddChangeIdToCommitMessage(options, args))
        ref_to_push = 'HEAD'
        parent = ('%s/%s' % (gerrit_remote, branch))
        change_id = git_footers.get_footer_change_id(change_desc.description)[0]
    assert change_desc
    commits = RunGitSilent(['rev-list', ('%s..%s' % (parent, ref_to_push))]).splitlines()
    if (len(commits) > 1):
        print(('WARNING: This will upload %d commits. Run the following command to see which commits will be uploaded: ' % len(commits)))
        print(('git log %s..%s' % (parent, ref_to_push)))
        print('You can also use `git squash-branch` to squash these into a single commit.')
        ask_for_data('About to upload; enter to confirm.')
    if (options.reviewers or options.tbr_owners):
        change_desc.update_reviewers(options.reviewers, options.tbr_owners, change)
    refspec_opts = []
    if options.title:
        if ('_' in options.title):
            print('WARNING: underscores in title will be converted to spaces.')
        refspec_opts.append(('m=' + options.title.replace(' ', '_')))
    if options.send_mail:
        if (not change_desc.get_reviewers()):
            DieWithError('Must specify reviewers to send email.')
        refspec_opts.append('notify=ALL')
    else:
        refspec_opts.append('notify=NONE')
    cc = self.GetCCList().split(',')
    if options.cc:
        cc.extend(options.cc)
    cc = filter(None, cc)
    if cc:
        refspec_opts.extend((('cc=' + email.strip()) for email in cc))
    if change_desc.get_reviewers():
        refspec_opts.extend((('r=' + email.strip()) for email in change_desc.get_reviewers()))
    refspec_suffix = ''
    if refspec_opts:
        refspec_suffix = ('%' + ','.join(refspec_opts))
        assert (' ' not in refspec_suffix), ('spaces not allowed in refspec: "%s"' % refspec_suffix)
    refspec = ('%s:refs/for/%s%s' % (ref_to_push, branch, refspec_suffix))
    push_stdout = gclient_utils.CheckCallAndFilter(['git', 'push', gerrit_remote, refspec], print_stdout=True, filter_fn=(lambda _: sys.stdout.flush()))
    if options.squash:
        regex = re.compile('remote:\\s+https?://[\\w\\-\\.\\/]*/(\\d+)\\s.*')
        change_numbers = [m.group(1) for m in map(regex.match, push_stdout.splitlines()) if m]
        if (len(change_numbers) != 1):
            DieWithError(('Created|Updated %d issues on Gerrit, but only 1 expected.\nChange-Id: %s' % (len(change_numbers), change_id)))
        self.SetIssue(change_numbers[0])
        RunGit(['config', ('branch.%s.gerritsquashhash' % self.GetBranch()), ref_to_push])
    return 0
Upload the current branch to Gerrit.
def CMDUploadChange(self, options, args, change):
    
    if (options.squash and options.no_squash):
        DieWithError('Can only use one of --squash or --no-squash')
    if ((not options.squash) and (not options.no_squash)):
        options.squash = settings.GetSquashGerritUploads()
    elif options.no_squash:
        options.squash = False
    gerrit_remote = 'origin'
    (remote, remote_branch) = self.GetRemoteBranch()
    branch = GetTargetRef(remote, remote_branch, options.target_branch, pending_prefix=)
    if options.squash:
        self._GerritCommitMsgHookCheck(offer_removal=(not options.force))
        if (not self.GetIssue()):
            message = RunGitSilent(['show', '--format=%B', '-s', ('refs/heads/git_cl_uploads/%s' % self.GetBranch())])
            if message:
                change_ids = git_footers.get_footer_change_id(message.strip())
                if (change_ids and (len(change_ids) == 1)):
                    details = self._GetChangeDetail(issue=change_ids[0])
                    if details:
                        print(('WARNING: found old upload in branch git_cl_uploads/%s corresponding to issue %s' % (self.GetBranch(), details['_number'])))
                        self.SetIssue(details['_number'])
                if (not self.GetIssue()):
                    DieWithError(('\nFound old upload in branch git_cl_uploads/%s, but failed to find corresponding Gerrit issue.\nIf you know the issue number, set it manually first:\n    git cl issue 123456\nIf you intended to upload this CL as new issue, just delete or rename the old upload branch:\n    git rename-branch git_cl_uploads/%s old_upload-%s\nAfter that, please run git cl upload again.' % tuple(([self.GetBranch()] * 3))))
        if self.GetIssue():
            message = self.GetDescription()
            if (not message):
                DieWithError(('failed to fetch description from current Gerrit issue %d\n%s' % (self.GetIssue(), self.GetIssueURL())))
            change_id = self._GetChangeDetail()['change_id']
            while True:
                footer_change_ids = git_footers.get_footer_change_id(message)
                if (footer_change_ids == [change_id]):
                    break
                if (not footer_change_ids):
                    message = git_footers.add_footer_change_id(message, change_id)
                    print('WARNING: appended missing Change-Id to issue description')
                    continue
                message = ('%s\n\nChange-Id: %s' % (message, change_id))
                print(('WARNING: issue %s has Change-Id footer(s):\n  %s\nbut issue has Change-Id %s, according to Gerrit.\nPlease, check the proposed correction to the description, and edit it if necessary but keep the "Change-Id: %s" footer\n' % (self.GetIssue(), '\n  '.join(footer_change_ids), change_id, change_id)))
                ask_for_data('Press enter to edit now, Ctrl+C to abort')
                if (not options.force):
                    change_desc = ChangeDescription(message)
                    change_desc.prompt()
                    message = change_desc.description
                    if (not message):
                        DieWithError('Description is empty. Aborting...')
            assert ([change_id] == git_footers.get_footer_change_id(message))
            change_desc = ChangeDescription(message)
        else:
            change_desc = ChangeDescription((options.message or CreateDescriptionFromLog(args)))
            if (not options.force):
                change_desc.prompt()
            if (not change_desc.description):
                DieWithError('Description is empty. Aborting...')
            message = change_desc.description
            change_ids = git_footers.get_footer_change_id(message)
            if (len(change_ids) > 1):
                DieWithError('too many Change-Id footers, at most 1 allowed.')
            if (not change_ids):
                message = git_footers.add_footer_change_id(message, GenerateGerritChangeId(message))
                change_desc.set_description(message)
                change_ids = git_footers.get_footer_change_id(message)
                assert (len(change_ids) == 1)
            change_id = change_ids[0]
        (remote, upstream_branch) = self.FetchUpstreamTuple(self.GetBranch())
        if (remote is '.'):
            upstream_branch_name = scm.GIT.ShortBranchName(upstream_branch)
            parent = RunGit(['config', ('branch.%s.gerritsquashhash' % upstream_branch_name)], error_ok=True).strip()
            if ((not parent) or (RunGitSilent(['rev-parse', (upstream_branch + ':')]) != RunGitSilent(['rev-parse', (parent + ':')]))):
                DieWithError(("Upload upstream branch %s first.\nNote: maybe you've uploaded it with --no-squash or with an old version of depot_tools. If so, then re-upload it with:\n    git cl upload --squash\n" % upstream_branch_name))
        else:
            parent = self.GetCommonAncestorWithUpstream()
        tree = RunGit(['rev-parse', 'HEAD:']).strip()
        ref_to_push = RunGit(['commit-tree', tree, '-p', parent, '-m', message]).strip()
    else:
        change_desc = ChangeDescription((options.message or CreateDescriptionFromLog(args)))
        if (not change_desc.description):
            DieWithError('Description is empty. Aborting...')
        if (not git_footers.get_footer_change_id(change_desc.description)):
            DownloadGerritHook(False)
            change_desc.set_description(self._AddChangeIdToCommitMessage(options, args))
        ref_to_push = 'HEAD'
        parent = ('%s/%s' % (gerrit_remote, branch))
        change_id = git_footers.get_footer_change_id(change_desc.description)[0]
    assert change_desc
    commits = RunGitSilent(['rev-list', ('%s..%s' % (parent, ref_to_push))]).splitlines()
    if (len(commits) > 1):
        print(('WARNING: This will upload %d commits. Run the following command to see which commits will be uploaded: ' % len(commits)))
        print(('git log %s..%s' % (parent, ref_to_push)))
        print('You can also use `git squash-branch` to squash these into a single commit.')
        ask_for_data('About to upload; enter to confirm.')
    if (options.reviewers or options.tbr_owners):
        change_desc.update_reviewers(options.reviewers, options.tbr_owners, change)
    refspec_opts = []
    if options.title:
        if ('_' in options.title):
            print('WARNING: underscores in title will be converted to spaces.')
        refspec_opts.append(('m=' + options.title.replace(' ', '_')))
    if options.send_mail:
        if (not change_desc.get_reviewers()):
            DieWithError('Must specify reviewers to send email.')
        refspec_opts.append('notify=ALL')
    else:
        refspec_opts.append('notify=NONE')
    cc = self.GetCCList().split(',')
    if options.cc:
        cc.extend(options.cc)
    cc = filter(None, cc)
    if cc:
        refspec_opts.extend((('cc=' + email.strip()) for email in cc))
    if change_desc.get_reviewers():
        refspec_opts.extend((('r=' + email.strip()) for email in change_desc.get_reviewers()))
    refspec_suffix = 
    if refspec_opts:
        refspec_suffix = ('%' + ','.join(refspec_opts))
        assert (' ' not in refspec_suffix), ('spaces not allowed in refspec: "%s"' % refspec_suffix)
    refspec = ('%s:refs/for/%s%s' % (ref_to_push, branch, refspec_suffix))
    push_stdout = gclient_utils.CheckCallAndFilter(['git', 'push', gerrit_remote, refspec], print_stdout=True, filter_fn=(lambda _: sys.stdout.flush()))
    if options.squash:
        regex = re.compile('remote:\\s+https?://[\\w\\-\\.\\/]*/(\\d+)\\s.*')
        change_numbers = [m.group(1) for m in map(regex.match, push_stdout.splitlines()) if m]
        if (len(change_numbers) != 1):
            DieWithError(('Created|Updated %d issues on Gerrit, but only 1 expected.\nChange-Id: %s' % (len(change_numbers), change_id)))
        self.SetIssue(change_numbers[0])
        RunGit(['config', ('branch.%s.gerritsquashhash' % self.GetBranch()), ref_to_push])
    return 0