From bfd5853957d53e231c0ccdf74004f726709aa07e Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 26 Aug 2013 13:23:11 -0700 Subject: [PATCH] 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 --- zuul/merger.py | 15 +++++++++++---- zuul/scheduler.py | 7 ++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/zuul/merger.py b/zuul/merger.py index 218f7f22f5..c16ab3be6a 100644 --- a/zuul/merger.py +++ b/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) diff --git a/zuul/scheduler.py b/zuul/scheduler.py index 23a504ea9b..75ab03a666 100644 --- a/zuul/scheduler.py +++ b/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,