Patchwork [3,of,8] util: expose an "available" API on compression engines

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 11, 2016, 9:23 a.m.
Message ID <13fccc619c0d8627d05d.1478856215@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17470/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 11, 2016, 9:23 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1478847828 28800
#      Thu Nov 10 23:03:48 2016 -0800
# Node ID 13fccc619c0d8627d05d07f4a51d67a87bf2ca62
# Parent  32c2b8ca42a574f83426eaa19c89a8ff51c0e6de
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.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2955,6 +2955,15 @@  class compressionengine(object):
         """
         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.