Fetch specific refs on ref-updated events

The current behavior is that for every event, run
'git remote origin update', which is quite a bit of overhead and
doesn't match what the comments say should be happening.  The goal
is to ensure that when new tags arrive, we have them locally in
our repo.  It's also not a bad idea for us to keep up with remote
branch movements as well.

This updates the event pre-processor to fetch the ref for each
ref-updated event as they are processed.  This is much faster than
the git remote update that was happening before.  It also adds
a git remote update to the repo initialization step so that when
Zuul starts, it will pick up any remote changes since it last ran.

Change-Id: I671bb43eddf41c7403de53bb4a223762101adc3c
This commit is contained in:
James E. Blair 2013-08-26 13:23:11 -07:00
parent 19deff2a49
commit bfd5853957
2 changed files with 15 additions and 7 deletions

View File

@ -34,6 +34,8 @@ class Repo(object):
self._initialized = False self._initialized = False
try: try:
self._ensure_cloned() self._ensure_cloned()
# Pick up any tags or branch updates since we last ran:
self.update()
except: except:
self.log.exception("Unable to initialize repo for %s" % remote) self.log.exception("Unable to initialize repo for %s" % remote)
@ -182,13 +184,18 @@ class Merger(object):
r.recreateRepoObject() r.recreateRepoObject()
return r return r
def updateRepo(self, project): def updateRepo(self, project, ref=None):
repo = self.getRepo(project) repo = self.getRepo(project)
try: try:
self.log.info("Updating local repository %s", project) if ref:
repo.update() self.log.debug("Fetching ref %s for local repository %s" %
(ref, project))
repo.fetch(ref)
else:
self.log.info("Updating local repository %s" % project)
repo.update()
except: except:
self.log.exception("Unable to update %s", project) self.log.exception("Unable to update %s" % project)
def _mergeChange(self, change, ref, target_ref): def _mergeChange(self, change, ref, target_ref):
repo = self.getRepo(change.project) repo = self.getRepo(change.project)

View File

@ -551,13 +551,14 @@ class Scheduler(threading.Thread):
return return
# Preprocessing for ref-update events # Preprocessing for ref-update events
if hasattr(event, 'refspec'): if event.ref:
# Make sure the local git repo is up-to-date with the remote one. # Make sure the local git repo is up-to-date with the remote one.
# We better have the new ref before enqueuing the changes. # We better have the new ref before enqueuing the changes.
# This is done before enqueuing the changes to avoid calling an # This is done before enqueuing the changes to avoid calling an
# update per pipeline accepting the change. # update per pipeline accepting the change.
self.log.info("Fetching references for %s" % project) self.log.info("Fetching updated ref %s for %s" %
self.merger.updateRepo(project) (event.ref, project))
self.merger.updateRepo(project, event.ref)
for pipeline in self.layout.pipelines.values(): for pipeline in self.layout.pipelines.values():
change = event.getChange(project, change = event.getChange(project,