Browse Source

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
changes/75/43775/3
James E. Blair 9 years ago
parent
commit
bfd5853957
  1. 15
      zuul/merger.py
  2. 7
      zuul/scheduler.py

15
zuul/merger.py

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

7
zuul/scheduler.py

@ -551,13 +551,14 @@ class Scheduler(threading.Thread):
return
# 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.
# We better have the new ref before enqueuing the changes.
# This is done before enqueuing the changes to avoid calling an
# update per pipeline accepting the change.
self.log.info("Fetching references for %s" % project)
self.merger.updateRepo(project)
self.log.info("Fetching updated ref %s for %s" %
(event.ref, project))
self.merger.updateRepo(project, event.ref)
for pipeline in self.layout.pipelines.values():
change = event.getChange(project,

Loading…
Cancel
Save