Example #1
0
def git_cl_uploader(config, message, file_list):
    """Create a commit in the current git branch; upload via git-cl.

    Assumes that you are already on the branch you want to be on.

    Args:
        config: (roll_deps.DepsRollConfig) object containing options.
        message: (string) the commit message, can be multiline.
        file_list: (list of strings) list of filenames to pass to `git add`.

    Returns:
        The output of `git cl issue`, if not config.skip_cl_upload, else ''.
    """

    git, vsp = config.git, config.vsp
    svn_info = str(get_svn_revision(config, 'HEAD'))

    for filename in file_list:
        assert os.path.exists(filename)
        vsp.check_call([git, 'add', filename])

    vsp.check_call([git, 'commit', '-q', '-m', message])

    git_cl = [
        git, 'cl', 'upload', '-f', '--bypass-hooks', '--bypass-watchlists'
    ]
    if config.cc_list:
        git_cl.append('--cc=%s' % config.cc_list)
    if config.reviewers_list:
        git_cl.append('--reviewers=%s' % config.reviewers_list)

    git_try = [
        git, 'cl', 'try', '-m', 'tryserver.chromium', '--revision', svn_info
    ]
    git_try.extend([arg for bot in config.cl_bot_list for arg in ('-b', bot)])

    branch_name = git_utils.git_branch_name(vsp.verbose)

    if config.skip_cl_upload:
        space = '   '
        print 'You should call:'
        print '%scd %s' % (space, os.getcwd())
        misc_utils.print_subprocess_args(space, [git, 'checkout', branch_name])
        misc_utils.print_subprocess_args(space, git_cl)
        if config.cl_bot_list:
            misc_utils.print_subprocess_args(space, git_try)
        print
        return ''
    else:
        vsp.check_call(git_cl)
        issue = vsp.strip_output([git, 'cl', 'issue'])
        if config.cl_bot_list:
            vsp.check_call(git_try)
        return issue
Example #2
0
def git_cl_uploader(config, message, file_list):
    """Create a commit in the current git branch; upload via git-cl.

    Assumes that you are already on the branch you want to be on.

    Args:
        config: (roll_deps.DepsRollConfig) object containing options.
        message: (string) the commit message, can be multiline.
        file_list: (list of strings) list of filenames to pass to `git add`.

    Returns:
        The output of `git cl issue`, if not config.skip_cl_upload, else ''.
    """

    git, vsp = config.git, config.vsp
    svn_info = str(get_svn_revision(config, 'HEAD'))

    for filename in file_list:
        assert os.path.exists(filename)
        vsp.check_call([git, 'add', filename])

    vsp.check_call([git, 'commit', '-q', '-m', message])

    git_cl = [git, 'cl', 'upload', '-f',
              '--bypass-hooks', '--bypass-watchlists']
    if config.cc_list:
        git_cl.append('--cc=%s' % config.cc_list)
    if config.reviewers_list:
        git_cl.append('--reviewers=%s' % config.reviewers_list)

    git_try = [
        git, 'cl', 'try', '-m', 'tryserver.chromium', '--revision', svn_info]
    git_try.extend([arg for bot in config.cl_bot_list for arg in ('-b', bot)])

    branch_name = git_utils.git_branch_name(vsp.verbose)

    if config.skip_cl_upload:
        space = '   '
        print 'You should call:'
        print '%scd %s' % (space, os.getcwd())
        misc_utils.print_subprocess_args(space, [git, 'checkout', branch_name])
        misc_utils.print_subprocess_args(space, git_cl)
        if config.cl_bot_list:
            misc_utils.print_subprocess_args(space, git_try)
        print
        return ''
    else:
        vsp.check_call(git_cl)
        issue = vsp.strip_output([git, 'cl', 'issue'])
        if config.cl_bot_list:
            vsp.check_call(git_try)
        return issue
def add_codereview_message(codereview_url, message, checkout_path,
                           skip_cl_upload, verbose, reviewers, cclist):
    """Add a message to a given codereview.

    Args:
        codereview_url: (string) we will extract the issue number from
            this url, or this could simply be the issue number.
        message: (string) will be passed to `git cl upload -m $MESSAGE`
        checkout_path: (string) location of the git
            repository checkout to be used.
        skip_cl_upload: (boolean) if true, don't actually
            add the message and keep the temporary branch around.
        verbose: (boolean) print out details useful for debugging.
        reviewers: (string) comma-separated list of reviewers
        cclist: (string) comma-separated list of addresses to be
            carbon-copied
    """
    # pylint: disable=I0011,R0913
    git = git_utils.git_executable()
    issue = codereview_url.strip('/').split('/')[-1]
    vsp = misc_utils.VerboseSubprocess(verbose)
    if skip_cl_upload:
        branch_name = 'issue_%s' % issue
    else:
        branch_name = None
    upstream = 'origin/master'

    with misc_utils.ChangeDir(checkout_path, verbose):
        vsp.check_call([git, 'fetch', '-q', 'origin'])

        with git_utils.ChangeGitBranch(branch_name, upstream, verbose):
            vsp.check_call([git, 'cl', 'patch', issue])

            git_upload = [
                git, 'cl', 'upload', '-t', 'bot report', '-m', message]
            if cclist:
                git_upload.append('--cc=' + cclist)
            if reviewers:
                git_upload.append('--reviewers=' + reviewers)

            if skip_cl_upload:
                branch_name = git_utils.git_branch_name(verbose)
                space = '    '
                print 'You should call:'
                misc_utils.print_subprocess_args(space, ['cd', os.getcwd()])
                misc_utils.print_subprocess_args(
                    space, [git, 'checkout', branch_name])
                misc_utils.print_subprocess_args(space, git_upload)
            else:
                vsp.check_call(git_upload)
                print vsp.check_output([git, 'cl', 'issue'])
def add_codereview_message(codereview_url, message, checkout_path,
                           skip_cl_upload, verbose, reviewers, cclist):
    """Add a message to a given codereview.

    Args:
        codereview_url: (string) we will extract the issue number from
            this url, or this could simply be the issue number.
        message: (string) will be passed to `git cl upload -m $MESSAGE`
        checkout_path: (string) location of the git
            repository checkout to be used.
        skip_cl_upload: (boolean) if true, don't actually
            add the message and keep the temporary branch around.
        verbose: (boolean) print out details useful for debugging.
        reviewers: (string) comma-separated list of reviewers
        cclist: (string) comma-separated list of addresses to be
            carbon-copied
    """
    # pylint: disable=I0011,R0913
    git = git_utils.git_executable()
    issue = codereview_url.strip('/').split('/')[-1]
    vsp = misc_utils.VerboseSubprocess(verbose)
    if skip_cl_upload:
        branch_name = 'issue_%s' % issue
    else:
        branch_name = None
    upstream = 'origin/master'

    with misc_utils.ChangeDir(checkout_path, verbose):
        vsp.check_call([git, 'fetch', '-q', 'origin'])

        with git_utils.ChangeGitBranch(branch_name, upstream, verbose):
            vsp.check_call([git, 'cl', 'patch', issue])

            git_upload = [
                git, 'cl', 'upload', '-t', 'bot report', '-m', message]
            if cclist:
                git_upload.append('--cc=' + cclist)
            if reviewers:
                git_upload.append('--reviewers=' + reviewers)

            if skip_cl_upload:
                branch_name = git_utils.git_branch_name(verbose)
                space = '    '
                print 'You should call:'
                misc_utils.print_subprocess_args(space, ['cd', os.getcwd()])
                misc_utils.print_subprocess_args(
                    space, [git, 'checkout', branch_name])
                misc_utils.print_subprocess_args(space, git_upload)
            else:
                vsp.check_call(git_upload)
                print vsp.check_output([git, 'cl', 'issue'])
Example #5
0
def roll_deps(config, revision, git_hash):
    """Upload changed DEPS and a whitespace change.

    Given the correct git_hash, create two Reitveld issues.

    Args:
        config: (roll_deps.DepsRollConfig) object containing options.
        revision: (int) Skia SVN revision.
        git_hash: (string) Skia Git hash.

    Returns:
        a tuple containing textual description of the two issues.

    Raises:
        OSError: failed to execute git or git-cl.
        subprocess.CalledProcessError: git returned unexpected status.
    """

    git = config.git
    with misc_utils.ChangeDir(config.chromium_path, config.verbose):
        config.vsp.check_call([git, 'fetch', '-q', 'origin'])

        old_revision = misc_utils.ReSearch.search_within_output(
            config.verbose, '"skia_revision": "(?P<return>[0-9]+)",', None,
            [git, 'show', 'origin/master:DEPS'])
        assert old_revision
        if revision == int(old_revision):
            print 'DEPS is up to date!'
            return (None, None)

        master_hash = config.vsp.strip_output(
            [git, 'show-ref', 'origin/master', '--hash'])
        master_revision = get_svn_revision(config, 'origin/master')

        # master_hash[8] gives each whitespace CL a unique name.
        if config.save_branches:
            branch = 'control_%s' % master_hash[:8]
        else:
            branch = None
        message = ('whitespace change %s\n\n'
                   'Chromium base revision: %d / %s\n\n'
                   'This CL was created by Skia\'s roll_deps.py script.\n'
                  ) % (master_hash[:8], master_revision, master_hash[:8])
        with git_utils.ChangeGitBranch(branch, 'origin/master',
                                       config.verbose):
            branch = git_utils.git_branch_name(config.vsp.verbose)

            with open('build/whitespace_file.txt', 'a') as output_stream:
                output_stream.write('\nCONTROL\n')

            whitespace_cl = git_cl_uploader(
                config, message, ['build/whitespace_file.txt'])

            control_url = misc_utils.ReSearch.search_within_string(
                whitespace_cl, '(?P<return>https?://[^) ]+)', '?')
            if config.save_branches:
                whitespace_cl = '%s\n    branch: %s' % (whitespace_cl, branch)

        if config.save_branches:
            branch = 'roll_%d_%s' % (revision, master_hash[:8])
        else:
            branch = None
        message = (
            'roll skia DEPS to %d\n\n'
            'Chromium base revision: %d / %s\n'
            'Old Skia revision: %s\n'
            'New Skia revision: %d\n'
            'Control CL: %s\n\n'
            'This CL was created by Skia\'s roll_deps.py script.\n\n'
            'Bypassing commit queue trybots:\n'
            'NOTRY=true\n'
            % (revision, master_revision, master_hash[:8],
               old_revision, revision, control_url))
        with git_utils.ChangeGitBranch(branch, 'origin/master',
                                       config.verbose):
            branch = git_utils.git_branch_name(config.vsp.verbose)

            change_skia_deps(revision, git_hash, 'DEPS')
            deps_cl = git_cl_uploader(config, message, ['DEPS'])
            if config.save_branches:
                deps_cl = '%s\n    branch: %s' % (deps_cl, branch)

        return deps_cl, whitespace_cl
Example #6
0
def roll_deps(config, revision, git_hash):
    """Upload changed DEPS and a whitespace change.

    Given the correct git_hash, create two Reitveld issues.

    Args:
        config: (roll_deps.DepsRollConfig) object containing options.
        revision: (int) Skia SVN revision.
        git_hash: (string) Skia Git hash.

    Returns:
        a tuple containing textual description of the two issues.

    Raises:
        OSError: failed to execute git or git-cl.
        subprocess.CalledProcessError: git returned unexpected status.
    """

    git = config.git
    with misc_utils.ChangeDir(config.chromium_path, config.verbose):
        config.vsp.check_call([git, 'fetch', '-q', 'origin'])

        old_revision = misc_utils.ReSearch.search_within_output(
            config.verbose, '"skia_revision": "(?P<return>[0-9]+)",', None,
            [git, 'show', 'origin/master:DEPS'])
        assert old_revision
        if revision == int(old_revision):
            print 'DEPS is up to date!'
            return (None, None)

        master_hash = config.vsp.strip_output(
            [git, 'show-ref', 'origin/master', '--hash'])
        master_revision = get_svn_revision(config, 'origin/master')

        # master_hash[8] gives each whitespace CL a unique name.
        if config.save_branches:
            branch = 'control_%s' % master_hash[:8]
        else:
            branch = None
        message = ('whitespace change %s\n\n'
                   'Chromium base revision: %d / %s\n\n'
                   'This CL was created by Skia\'s roll_deps.py script.\n') % (
                       master_hash[:8], master_revision, master_hash[:8])
        with git_utils.ChangeGitBranch(branch, 'origin/master',
                                       config.verbose):
            branch = git_utils.git_branch_name(config.vsp.verbose)

            with open('build/whitespace_file.txt', 'a') as output_stream:
                output_stream.write('\nCONTROL\n')

            whitespace_cl = git_cl_uploader(config, message,
                                            ['build/whitespace_file.txt'])

            control_url = misc_utils.ReSearch.search_within_string(
                whitespace_cl, '(?P<return>https?://[^) ]+)', '?')
            if config.save_branches:
                whitespace_cl = '%s\n    branch: %s' % (whitespace_cl, branch)

        if config.save_branches:
            branch = 'roll_%d_%s' % (revision, master_hash[:8])
        else:
            branch = None
        message = ('roll skia DEPS to %d\n\n'
                   'Chromium base revision: %d / %s\n'
                   'Old Skia revision: %s\n'
                   'New Skia revision: %d\n'
                   'Control CL: %s\n\n'
                   'This CL was created by Skia\'s roll_deps.py script.\n\n'
                   'Bypassing commit queue trybots:\n'
                   'NOTRY=true\n' %
                   (revision, master_revision, master_hash[:8], old_revision,
                    revision, control_url))
        with git_utils.ChangeGitBranch(branch, 'origin/master',
                                       config.verbose):
            branch = git_utils.git_branch_name(config.vsp.verbose)

            change_skia_deps(revision, git_hash, 'DEPS')
            deps_cl = git_cl_uploader(config, message, ['DEPS'])
            if config.save_branches:
                deps_cl = '%s\n    branch: %s' % (deps_cl, branch)

        return deps_cl, whitespace_cl