Commits

Michał Górny committed 25c9243

Add cache support.

  • Participants
  • Parent commits a2b3a8b

Comments (0)

Files changed (2)

File smartliverebuild/core.py

 			filters = (opts.filter_packages or []) + (cliargs or [])
 			filt = PackageFilter(filters)
 			getvcs = VCSLoader(remote_only = opts.remote_only)
+			cache = {}
 
 			try:
 				for pkg in pm.installed.filter(filt):
 							if vcscl is not None:
 								vcs = vcscl(str(pkg.slotted_atom),
 										environ = pkg.environ,
-										opts = opts)
+										opts = opts,
+										cache = cache)
 								processes.append(vcs)
 								loop_iter()
 					except KeyboardInterrupt:

File smartliverebuild/vcs/__init__.py

 		""" A package ID for update requestor. """
 		return self._cpv
 
-	def __init__(self, cpv, environ, opts):
+	def __init__(self, cpv, environ, opts, cache = None):
 		""" Initialize the VCS class for package `cpv', storing it as
 			self.cpv. Get envvars from `environ' (self.reqenv + self.optenv).
 
 
 		self._cpv = cpv
 		self._opts = opts
+		self._cache = cache
 		self.env = environ.copy(*(self.reqenv + self.optenv))
 
 		missingvars = [v for v in self.reqenv if not self.env[v]]
 	def __call__(self, blocking = False):
 		""" Perform a single main loop iteration. """
 		if not self._running:
+			# try the cache
+			if self._cache is not None:
+				try:
+					rev = self._cache[str(self)]
+				except KeyError:
+					pass
+				else:
+					return self._finishupdate(rev)
+
 			self._startupdate()
 			self._running = True
 			if blocking:
 			if newrev is None:
 				raise Exception('update command failed to return a rev')
 
+			if self._cache is not None:
+				self._cache[str(self)] = newrev
 			return self._finishupdate(newrev)
 		else:
 			raise Exception('update command returned non-zero result')