changeset 47254:eac3591abbf4

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
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 21:04:55 +0200
parents b876f0bf7366
children ff9fd7107d11
files mercurial/configitems.py mercurial/revlog.py
diffstat 2 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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)