revlog: add a `_get_decompressor` method
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 03 May 2021 21:04:55 +0200
changeset 47265 eac3591abbf4
parent 47264 b876f0bf7366
child 47266 ff9fd7107d11
revlog: add a `_get_decompressor` method This logic is non-trivial and we will need to reuse it. Differential Revision: https://phab.mercurial-scm.org/D10651
mercurial/configitems.py
mercurial/revlog.py
--- a/mercurial/configitems.py	Mon May 03 19:46:25 2021 +0200
+++ b/mercurial/configitems.py	Mon May 03 21:04:55 2021 +0200
@@ -1163,7 +1163,8 @@
 # * sidedata compression
 # * introduce a proper solution to reduce the number of filelog related files.
 # * Improvement to consider
-#   - track compression mode in the index entris instead of the chunks
+#   - avoid compression header in chunk using the default compression?
+#   - forbid "inline" compression mode entirely?
 #   - split the data offset and flag field (the 2 bytes save are mostly trouble)
 #   - keep track of uncompressed -chunk- size (to preallocate memory better)
 #   - keep track of chain base or size (probably not that useful anymore)
--- a/mercurial/revlog.py	Mon May 03 19:46:25 2021 +0200
+++ b/mercurial/revlog.py	Mon May 03 21:04:55 2021 +0200
@@ -689,6 +689,20 @@
         # revlog.target instead of using `self.radix`
         return self.radix
 
+    def _get_decompressor(self, t):
+        try:
+            compressor = self._decompressors[t]
+        except KeyError:
+            try:
+                engine = util.compengines.forrevlogheader(t)
+                compressor = engine.revlogcompressor(self._compengineopts)
+                self._decompressors[t] = compressor
+            except KeyError:
+                raise error.RevlogError(
+                    _(b'unknown compression type %s') % binascii.hexlify(t)
+                )
+        return compressor
+
     @util.propertycache
     def _compressor(self):
         engine = util.compengines[self._compengine]
@@ -2375,17 +2389,7 @@
         elif t == b'u':
             return util.buffer(data, 1)
 
-        try:
-            compressor = self._decompressors[t]
-        except KeyError:
-            try:
-                engine = util.compengines.forrevlogheader(t)
-                compressor = engine.revlogcompressor(self._compengineopts)
-                self._decompressors[t] = compressor
-            except KeyError:
-                raise error.RevlogError(
-                    _(b'unknown compression type %s') % binascii.hexlify(t)
-                )
+        compressor = self._get_decompressor(t)
 
         return compressor.decompress(data)