comparison mercurial/util.py @ 30447:90933e4e44fd

util: check for compression engine availability before returning If a requested compression engine is registered but not available, requesting it will now abort. To be honest, I'm not sure if this is the appropriate mechanism for handling optional compression engines. I won't know until all uses of compression (bundles, wire protocol, revlogs, etc) are using the new API and zstd (our planned optional engine) is implemented. So this API could change.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 10 Nov 2016 23:15:02 -0800
parents 64d7275445d0
children 41a8106789ca
comparison
equal deleted inserted replaced
30446:64d7275445d0 30447:90933e4e44fd
3019 3019
3020 def forbundlename(self, bundlename): 3020 def forbundlename(self, bundlename):
3021 """Obtain a compression engine registered to a bundle name. 3021 """Obtain a compression engine registered to a bundle name.
3022 3022
3023 Will raise KeyError if the bundle type isn't registered. 3023 Will raise KeyError if the bundle type isn't registered.
3024
3025 Will abort if the engine is known but not available.
3024 """ 3026 """
3025 return self._engines[self._bundlenames[bundlename]] 3027 engine = self._engines[self._bundlenames[bundlename]]
3028 if not engine.available():
3029 raise error.Abort(_('compression engine %s could not be loaded') %
3030 engine.name())
3031 return engine
3026 3032
3027 def forbundletype(self, bundletype): 3033 def forbundletype(self, bundletype):
3028 """Obtain a compression engine registered to a bundle type. 3034 """Obtain a compression engine registered to a bundle type.
3029 3035
3030 Will raise KeyError if the bundle type isn't registered. 3036 Will raise KeyError if the bundle type isn't registered.
3037
3038 Will abort if the engine is known but not available.
3031 """ 3039 """
3032 return self._engines[self._bundletypes[bundletype]] 3040 engine = self._engines[self._bundletypes[bundletype]]
3041 if not engine.available():
3042 raise error.Abort(_('compression engine %s could not be loaded') %
3043 engine.name())
3044 return engine
3033 3045
3034 compengines = compressormanager() 3046 compengines = compressormanager()
3035 3047
3036 class compressionengine(object): 3048 class compressionengine(object):
3037 """Base class for compression engines. 3049 """Base class for compression engines.