def startService(self):
        # Initialize revision comparator with revisions from all changes
        # known to buildbot.
        yield self.comparator.initialize(self.master.db)

        # Get the head commit for each branch being polled.
        branches = yield self._get_branches()
        self.branch_heads.update(
            {branch: None
             for branch in branches.iterkeys()})
        self._merge_cursor_file()

        # Update any branch heads thatwere not present in the cursor file.
        for branch, branch_head in branches.iteritems():
            # Load latest revision for our branch if it wasn't in the cursor file.
            if not self.branch_heads[branch]:
                log.msg('GitilesPoller: Initial revision for branch %s is %s' %
                        (branch, branch_head))
                self.branch_heads[branch] = branch_head
            elif branch_head != self.branch_heads[branch]:
                log.msg(
                    'GitilesPoller: Cursor revision for branch %s is %s with HEAD '
                    '%s' % (branch, self.branch_heads[branch], branch_head))
            else:
                log.msg(
                    'GitilesPoller: Cursor revision for branch %s is HEAD at %s'
                    % (branch, branch_head))
        self._save_cursor_file()

        PollingChangeSource.startService(self)
Example #2
0
  def startService(self):
    # Initialize revision comparator with revisions from all changes
    # known to buildbot.
    yield self.comparator.initialize(self.master.db)

    # Get the head commit for each branch being polled.
    branches = yield self._get_branches()
    self.branch_heads.update({branch: None for branch in branches.iterkeys()})
    self._merge_cursor_file()

    # Update any branch heads thatwere not present in the cursor file.
    for branch, branch_head in branches.iteritems():
      # Load latest revision for our branch if it wasn't in the cursor file.
      if not self.branch_heads[branch]:
        log.msg('GitilesPoller: Initial revision for branch %s is %s' % (
            branch, branch_head))
        self.branch_heads[branch] = branch_head
      elif branch_head != self.branch_heads[branch]:
        log.msg('GitilesPoller: Cursor revision for branch %s is %s with HEAD '
                '%s' % (branch, self.branch_heads[branch], branch_head))
      else:
        log.msg('GitilesPoller: Cursor revision for branch %s is HEAD at %s' % (
                branch, branch_head))
    self._save_cursor_file()

    PollingChangeSource.startService(self)
Example #3
0
  def startService(self):
    if self.dry_run:
      PollingChangeSource.startService(self)
      return

    if not os.path.isabs(self.workdir):
      self.workdir = os.path.join(self.master.basedir, self.workdir)
      log.msg('RepoPoller: using workdir "%s"' % self.workdir)

    if not os.path.exists(os.path.join(self.workdir, '.repo')):
      d = self.initRepository()
      log.msg('RepoPoller: creating new repo checkout in %s' % self.workdir)
    else:
      d = defer.succeed(None)
      log.msg('RepoPoller: using pre-existing repo checkout.')

    d.addCallback(self.initHistory)
    def _success(*unused_args):
      self.comparator.initialized = True
    d.addCallback(_success)
    PollingChangeSource.startService(self)
    def _failure(failure):
      log.msg('RepoPoller: unable to start service.')
      self.stopService()
      return failure
    d.addErrback(_failure)
  def startService(self):
    # Initialize revision comparator with revisions from all changes
    # known to buildbot.
    yield self.comparator.initialize(self.master.db)

    # Get the head commit for each branch being polled.
    branches = yield self._get_branches()
    for branch, branch_head in branches.iteritems():
      log.msg('GitilesPoller: Initial revision for branch %s is %s' % (
          branch, branch_head))
      self.branch_heads[branch] = branch_head

    PollingChangeSource.startService(self)
Example #5
0
    def startService(self):
        # Initialize revision comparator with revisions from all changes
        # known to buildbot.
        yield self.comparator.initialize(self.master.db)

        # Get the head commit for each branch being polled.
        branches = yield self._get_branches()
        for branch, branch_head in branches.iteritems():
            log.msg('GitilesPoller: Initial revision for branch %s is %s' %
                    (branch, branch_head))
            self.branch_heads[branch] = branch_head

        PollingChangeSource.startService(self)
  def startService(self):
    def stop(err):
      self._log('Failed to initialize revision history for', self.repo_url)

      # In verbose mode, stderr has already been emitted.
      if not self.verbose and err.rstrip():
        self._log('stderr:\n%s' % err.rstrip())

      return self.stopService()

    self._log('Initializing revision history of', self.repo_url)

    out, err, ret = yield self._git(
      'rev-parse', '--git-dir', '--is-bare-repository')
    out = out.splitlines()

    # Git commands are executed from inside the working directory, meaning
    # that relative to where the command was executed, --git-dir should be ".".
    if ret or len(out) != 2 or out[0] != '.' or out[1] != 'true':
      self._log('Working directory did not contain a mirrored repository')
      shutil.rmtree(self.workdir)
      os.makedirs(self.workdir)
      should_clone = True
    else:
      should_clone = False

    if should_clone:
      self._log('Cloning mirror of', self.repo_url)
      out, err, ret = yield self._git('clone', '--mirror', self.repo_url, '.')
      if ret:
        yield stop(err)
        return

    out, err, ret = yield self._git('remote')
    if ret:
      yield stop(err)
      return

    for remote in out.splitlines():
      out, err, ret = yield self._git('remote', 'remove', remote)
      if ret:
        yield stop(err)
        return

    out, err, ret = yield self._git('remote', 'add', 'origin', self.repo_url)
    if ret:
      yield stop(err)
      return

    for remote in self.additional_remotes:
      self._log('Adding remote', remote.repo_url)

      out, err, ret = yield self._git(
        'remote', 'add', remote.name, remote.repo_url)
      if ret:
        yield stop(err)
        return

      for (remote_ref, local_ref) in remote.ref_map.iteritems():
        out, err, ret = yield self._git(
          'config',
          '--add',
          'remote.%s.fetch' % remote.name,
          '+%s:%s' % (remote_ref, local_ref),
        )
        if ret:
          yield stop(err)
          return

    yield self._log('Fetching origin for', self.repo_url)
    out, err, ret = yield self._git('fetch', '--all')
    if ret:
      yield stop(err)
      return

    new_branch_heads = {}

    for branch in self.branch_heads:
      out, err, ret = yield self._git('rev-parse', 'origin/%s' % branch)
      if ret:
        yield stop(err)
      self._log(branch, 'at', out.rstrip())
      new_branch_heads[branch] = out.rstrip()

    # Don't exclude the specified excluded_refs here so the
    # comparator has the complete picture. Only exclude in
    # the polling operation, so those refs don't get passed
    # to the master.
    out, err, ret = yield self._git(
      'rev-list',
      '--date-order',
      '--reverse',
      *new_branch_heads.values())
    if ret:
      yield stop(err)
    revisions = out.splitlines()

    # Now that all git operations have succeeded and the poll is complete,
    # update our view of the branch heads and revision order.
    self.branch_heads.update(new_branch_heads)
    self.comparator.addRevisions(revisions)

    yield PollingChangeSource.startService(self)
 def startService(self):
     # Initialize revision comparator with revisions from all changes
     # known to buildbot.
     yield self.comparator.initialize(self.master.db)
     PollingChangeSource.startService(self)
Example #8
0
    def startService(self):
        def stop(err):
            self._log('Failed to initialize revision history for',
                      self.repo_url)

            # In verbose mode, stderr has already been emitted.
            if not self.verbose and err.rstrip():
                self._log('stderr:\n%s' % err.rstrip())

            return self.stopService()

        self._log('Initializing revision history of', self.repo_url)

        out, err, ret = yield self._git('rev-parse', '--git-dir',
                                        '--is-bare-repository')
        out = out.splitlines()

        # Git commands are executed from inside the working directory, meaning
        # that relative to where the command was executed, --git-dir should be ".".
        if ret or len(out) != 2 or out[0] != '.' or out[1] != 'true':
            self._log(
                'Working directory did not contain a mirrored repository')
            shutil.rmtree(self.workdir)
            os.makedirs(self.workdir)
            should_clone = True
        else:
            should_clone = False

        if should_clone:
            self._log('Cloning mirror of', self.repo_url)
            out, err, ret = yield self._git('clone', '--mirror', self.repo_url,
                                            '.')
            if ret:
                yield stop(err)
                return

        out, err, ret = yield self._git('remote')
        if ret:
            yield stop(err)
            return

        for remote in out.splitlines():
            out, err, ret = yield self._git('remote', 'remove', remote)
            if ret:
                yield stop(err)
                return

        out, err, ret = yield self._git('remote', 'add', 'origin',
                                        self.repo_url)
        if ret:
            yield stop(err)
            return

        for remote in self.additional_remotes:
            self._log('Adding remote', remote.repo_url)

            out, err, ret = yield self._git('remote', 'add', remote.name,
                                            remote.repo_url)
            if ret:
                yield stop(err)
                return

            out, err, ret = yield self._git('config', '--unset',
                                            'remote.%s.fetch' % remote.name)
            if ret:
                yield stop(err)
                return

            for (remote_ref, local_ref) in remote.ref_map.iteritems():
                out, err, ret = yield self._git(
                    'config',
                    '--add',
                    'remote.%s.fetch' % remote.name,
                    '+%s:%s' % (remote_ref, local_ref),
                )
                if ret:
                    yield stop(err)
                    return

        yield self._log('Fetching remotes for', self.repo_url)
        out, err, ret = yield self._git('fetch', '--all')
        if ret:
            yield stop(err)
            return

        new_branch_heads = {}

        for branch in self.branch_heads:
            out, err, ret = yield self._git('rev-parse', '%s' % branch)
            if ret:
                yield stop(err)
            self._log(branch, 'at', out.rstrip())
            new_branch_heads[branch] = out.rstrip()

        # Don't exclude the specified excluded_refs here so the
        # comparator has the complete picture. Only exclude in
        # the polling operation, so those refs don't get passed
        # to the master.
        out, err, ret = yield self._git('rev-list',
                                        '--date-order', '--reverse',
                                        *new_branch_heads.values())
        if ret:
            yield stop(err)
        revisions = out.splitlines()

        # Now that all git operations have succeeded and the poll is complete,
        # update our view of the branch heads and revision order.
        self.branch_heads.update(new_branch_heads)
        self.comparator.addRevisions(revisions)

        yield PollingChangeSource.startService(self)
 def setServiceParent(self, parent):
   PollingChangeSource.setServiceParent(self, parent)
   self._scheduler = parent
 def startService(self):
   # Initialize revision comparator with revisions from all changes
   # known to buildbot.
   yield self.comparator.initialize(self.master.db)
   PollingChangeSource.startService(self)