def start(self): self.__branches_info = get_branches_info( include_tracking_status=self.verbosity >= 1) if (self.verbosity >= 2): # Avoid heavy import unless necessary. from git_cl import get_cl_statuses, color_for_status, Changelist change_cls = [ Changelist(branchref='refs/heads/' + b) for b in self.__branches_info.keys() if b ] status_info = get_cl_statuses(change_cls, fine_grained=self.verbosity > 2, max_processes=self.maxjobs) # This is a blocking get which waits for the remote CL status to be # retrieved. for cl, status in status_info: self.__status_info[cl.GetBranch()] = (cl.GetIssueURL(), color_for_status(status), status) roots = set() # A map of parents to a list of their children. for branch, branch_info in self.__branches_info.items(): if not branch_info: continue parent = branch_info.upstream if self.__check_cycle(branch): continue if not self.__branches_info[parent]: branch_upstream = upstream(branch) # If git can't find the upstream, mark the upstream as gone. if branch_upstream: parent = branch_upstream else: self.__gone_branches.add(parent) # A parent that isn't in the branches info is a root. roots.add(parent) self.__parent_map[parent].append(branch) self.__current_branch = current_branch() self.__current_hash = hash_one('HEAD', short=True) self.__tag_set = tags() if roots: for root in sorted(roots): self.__append_branch(root) else: no_branches = OutputLine() no_branches.append('No User Branches') self.output.append(no_branches)
def _CheckLocalBranchMatchesPatchset(input_api, output_api): issue = input_api.change.issue cl = Changelist(issue=issue) patch_set = cl.GetMostRecentPatchset() patch_set_diff = cl.GetPatchSetDiff(issue, patch_set) local_diff = subprocess.check_output(['git', 'diff', 'origin/master']) with _WriteTemporaryFile(patch_set_diff) as patch_set_diff_file: with _WriteTemporaryFile(local_diff) as local_diff_file: diff_diff = subprocess.check_output( ['interdiff', patch_set_diff_file.name, local_diff_file.name]) if diff_diff: return [ output_api.PresubmitError( 'Local branch does not match patch set %s for issue %s. Revert or upload new changes to branch to resolve.\n\n%s' % (patch_set, issue, diff_diff)) ] return []
def main(): parser = argparse.ArgumentParser(description='') parser.add_argument("benchmarks", nargs="+", help="The benchmarks to run.") for option in sorted(BOTS): parser.add_argument(option, dest='bots', action='append_const', const=BOTS[option], help='Add %s trybot.' % BOTS[option]) options = parser.parse_args() if not options.bots: print 'No trybots specified. Using default %s.' % ','.join( DEFAULT_BOTS) options.bots = DEFAULT_BOTS cl = Changelist() if not cl.GetIssue(): print 'Need to upload first' return 1 props = cl.GetIssueProperties() if props.get('closed'): print 'Cannot send tryjobs for a closed CL' return 1 if props.get('private'): print 'Cannot use trybots with private issue' return 1 if not options.benchmarks: print 'Please specify the benchmarks to run as arguments.' return 1 masters = { 'internal.client.v8': dict( (b, options.benchmarks) for b in options.bots), } cl.RpcServer().trigger_distributed_try_jobs(cl.GetIssue(), cl.GetMostRecentPatchset(), cl.GetBranch(), False, None, masters) return 0
def main(tests): cl = Changelist() if not cl.GetIssue(): print 'Need to upload first' return 1 props = cl.GetIssueProperties() if props.get('closed'): print 'Cannot send tryjobs for a closed CL' return 1 if props.get('private'): print 'Cannot use trybots with private issue' return 1 if not tests: print 'Please specify the benchmarks to run as arguments.' return 1 masters = {'internal.client.v8': dict((b, tests) for b in BOTS)} cl.RpcServer().trigger_distributed_try_jobs( cl.GetIssue(), cl.GetMostRecentPatchset(), cl.GetBranch(), False, None, masters) return 0
def cherry_pick(target_branch, commit, auth_config): """Attempt to upload a cherry pick CL to rietveld. Args: target_branch: The branch to cherry pick onto. commit: The git hash of the commit to cherry pick. auth_config: auth.AuthConfig object with authentication configuration. """ author = config('user.email') description = '%s\n\n(cherry picked from commit %s)\n' % (run( 'show', '--pretty=%B', '--quiet', commit), commit) parent = run('show', '--pretty=%P', '--quiet', commit) print 'Found parent revision:', parent class Options(object): def __init__(self): self.emulate_svn_auto_props = False content_type, payload = EncodeMultipartFormData([ ('base', '%s@%s' % (Changelist().GetRemoteUrl(), target_branch)), ('cc', config('rietveld.cc')), ('content_upload', '1'), ('description', description), ('project', '%s@%s' % (config('rietveld.project'), target_branch)), ('subject', description.splitlines()[0]), ('user', author), ], [ ('data', 'data.diff', GitVCS(Options()).PostProcessDiff( run('diff', parent, commit))), ]) rietveld = Rietveld(config('rietveld.server'), auth_config, author) # pylint: disable=protected-access output = rietveld._send( '/upload', payload=payload, content_type=content_type, ).splitlines() # If successful, output will look like: # Issue created. URL: https://codereview.chromium.org/1234567890 # 1 # 10001 some/path/first.file # 10002 some/path/second.file # 10003 some/path/third.file if output[0].startswith('Issue created. URL: '): print output[0] issue = output[0].rsplit('/', 1)[-1] patchset = output[1] files = output[2:] for f in files: file_id, filename = f.split() mode = 'M' try: content = run('show', '%s:%s' % (parent, filename)) except subprocess2.CalledProcessError: # File didn't exist in the parent revision. content = '' mode = 'A' content_type, payload = EncodeMultipartFormData([ ('checksum', md5.md5(content).hexdigest()), ('filename', filename), ('is_current', 'False'), ('status', mode), ], [ ('data', filename, content), ]) # pylint: disable=protected-access print ' Uploading base file for %s:' % filename, rietveld._send( '/%s/upload_content/%s/%s' % (issue, patchset, file_id), payload=payload, content_type=content_type, ) try: content = run('show', '%s:%s' % (commit, filename)) except subprocess2.CalledProcessError: # File no longer exists in the new commit. content = '' mode = 'D' content_type, payload = EncodeMultipartFormData([ ('checksum', md5.md5(content).hexdigest()), ('filename', filename), ('is_current', 'True'), ('status', mode), ], [ ('data', filename, content), ]) # pylint: disable=protected-access print ' Uploading %s:' % filename, rietveld._send( '/%s/upload_content/%s/%s' % (issue, patchset, file_id), payload=payload, content_type=content_type, ) # pylint: disable=protected-access print 'Finalizing upload:', rietveld._send('/%s/upload_complete/1' % issue)