# HG changeset patch # User Gregory Szorc # Date 2016-11-11 07:15:02 # Node ID 90933e4e44fdbd727ed65480e67822141ae53f0e # Parent 64d7275445d0706c6cdbe2420c4014899aa33945 util: check for compression engine availability before returning If a requested compression engine is registered but not available, requesting it will now abort. To be honest, I'm not sure if this is the appropriate mechanism for handling optional compression engines. I won't know until all uses of compression (bundles, wire protocol, revlogs, etc) are using the new API and zstd (our planned optional engine) is implemented. So this API could change. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -3021,15 +3021,27 @@ class compressormanager(object): """Obtain a compression engine registered to a bundle name. Will raise KeyError if the bundle type isn't registered. + + Will abort if the engine is known but not available. """ - return self._engines[self._bundlenames[bundlename]] + engine = self._engines[self._bundlenames[bundlename]] + if not engine.available(): + raise error.Abort(_('compression engine %s could not be loaded') % + engine.name()) + return engine def forbundletype(self, bundletype): """Obtain a compression engine registered to a bundle type. Will raise KeyError if the bundle type isn't registered. + + Will abort if the engine is known but not available. """ - return self._engines[self._bundletypes[bundletype]] + engine = self._engines[self._bundletypes[bundletype]] + if not engine.available(): + raise error.Abort(_('compression engine %s could not be loaded') % + engine.name()) + return engine compengines = compressormanager()