util: expose an "available" API on compression engines
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 10 Nov 2016 23:03:48 -0800
changeset 30437 64d7275445d0
parent 30436 788ea4ac4388
child 30438 90933e4e44fd
util: expose an "available" API on compression engines When the zstd compression engine is introduced, it won't work in all installations, namely pure Python installs. So, we need a mechanism to declare whether a compression engine is available. We don't want to conditionally register the compression engine because it is sometimes useful to know when a compression engine name or encountered data is valid but just not available versus unknown.
mercurial/util.py
--- a/mercurial/util.py	Thu Nov 10 22:26:35 2016 -0800
+++ b/mercurial/util.py	Thu Nov 10 23:03:48 2016 -0800
@@ -3047,6 +3047,15 @@
         """
         raise NotImplementedError()
 
+    def available(self):
+        """Whether the compression engine is available.
+
+        The intent of this method is to allow optional compression engines
+        that may not be available in all installations (such as engines relying
+        on C extensions that may not be present).
+        """
+        return True
+
     def bundletype(self):
         """Describes bundle identifiers for this engine.