def _set_project_revisions(projects):
    """Sets the revisionExpr for a list of projects.

  Because of the limit of open file descriptors allowed, length of projects
  should not be overly large. Recommend calling this function multiple times
  with each call not exceeding NUM_BATCH_RETRIEVE_REVISIONID projects.

  @param projects: List of project objects to set the revionExpr for.
  """
    # Retrieve the commit id for each project based off of it's current
    # revisionExpr and it is not already a commit id.
    project_gitcmds = [
        (project,
         git_command.GitCommand(
             None, ['ls-remote', project.remote.url, project.revisionExpr],
             capture_stdout=True,
             cwd='/tmp')) for project in projects
        if not git_config.IsId(project.revisionExpr)
    ]
    for proj, gitcmd in project_gitcmds:
        if gitcmd.Wait():
            print('FATAL: Failed to retrieve revisionExpr for %s' % proj)
            sys.exit(1)
        revisionExpr = gitcmd.stdout.split('\t')[0]
        if not revisionExpr:
            raise (ManifestParseError(
                'Invalid SHA-1 revision project %s (%s)' %
                (proj.remote.url, proj.revisionExpr)))
        proj.revisionExpr = revisionExpr
Exemple #2
0
def _get_project_revision(args):
    """Worker for _set_project_revisions to lookup one project remote."""
    (i, url, expr) = args
    gitcmd = git_command.GitCommand(None, ['ls-remote', url, expr],
                                    capture_stdout=True,
                                    cwd='/tmp')
    rc = gitcmd.Wait()
    return (i, rc, gitcmd.stdout.split('\t', 1)[0])
Exemple #3
0
    def _SetProjectRevisions(self, projects, branch):
        """Sets the revisionExpr for a list of projects.

    Because of the limit of open file descriptors allowed, length of projects
    should not be overly large. Recommend calling this function multiple times
    with each call not exceeding NUM_BATCH_RETRIEVE_REVISIONID projects.

    @param projects: List of project objects to set the revionExpr for.
    @param branch: The remote branch to retrieve the SHA from. If branch is
                   None, 'HEAD' is used.
    """
        project_gitcmds = [
            (project,
             git_command.GitCommand(None,
                                    ['ls-remote', project.remote.url, branch],
                                    capture_stdout=True))
            for project in projects
        ]
        for proj, gitcmd in project_gitcmds:
            if gitcmd.Wait():
                print('FATAL: Failed to retrieve revisionID for %s' % project)
                sys.exit(1)
            proj.revisionExpr = gitcmd.stdout.split('\t')[0]