changeset 30438:90933e4e44fd

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 10 Nov 2016 23:15:02 -0800
parents 64d7275445d0
children 71b368e3b590
files mercurial/util.py
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Thu Nov 10 23:03:48 2016 -0800
+++ b/mercurial/util.py	Thu Nov 10 23:15:02 2016 -0800
@@ -3021,15 +3021,27 @@
         """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()