comparison mercurial/revlog.py @ 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
comparison
equal deleted inserted replaced
47253:b876f0bf7366 47254:eac3591abbf4
686 def display_id(self): 686 def display_id(self):
687 """The public facing "ID" of the revlog that we use in message""" 687 """The public facing "ID" of the revlog that we use in message"""
688 # Maybe we should build a user facing representation of 688 # Maybe we should build a user facing representation of
689 # revlog.target instead of using `self.radix` 689 # revlog.target instead of using `self.radix`
690 return self.radix 690 return self.radix
691
692 def _get_decompressor(self, t):
693 try:
694 compressor = self._decompressors[t]
695 except KeyError:
696 try:
697 engine = util.compengines.forrevlogheader(t)
698 compressor = engine.revlogcompressor(self._compengineopts)
699 self._decompressors[t] = compressor
700 except KeyError:
701 raise error.RevlogError(
702 _(b'unknown compression type %s') % binascii.hexlify(t)
703 )
704 return compressor
691 705
692 @util.propertycache 706 @util.propertycache
693 def _compressor(self): 707 def _compressor(self):
694 engine = util.compengines[self._compengine] 708 engine = util.compengines[self._compengine]
695 return engine.revlogcompressor(self._compengineopts) 709 return engine.revlogcompressor(self._compengineopts)
2373 elif t == b'\0': 2387 elif t == b'\0':
2374 return data 2388 return data
2375 elif t == b'u': 2389 elif t == b'u':
2376 return util.buffer(data, 1) 2390 return util.buffer(data, 1)
2377 2391
2378 try: 2392 compressor = self._get_decompressor(t)
2379 compressor = self._decompressors[t]
2380 except KeyError:
2381 try:
2382 engine = util.compengines.forrevlogheader(t)
2383 compressor = engine.revlogcompressor(self._compengineopts)
2384 self._decompressors[t] = compressor
2385 except KeyError:
2386 raise error.RevlogError(
2387 _(b'unknown compression type %s') % binascii.hexlify(t)
2388 )
2389 2393
2390 return compressor.decompress(data) 2394 return compressor.decompress(data)
2391 2395
2392 def _addrevision( 2396 def _addrevision(
2393 self, 2397 self,