exchange: obtain compression engines from the registrar
util.compengines has knowledge of all registered compression engines
and the metadata that associates them with various bundle types.
This patch removes the now redundant declaration of this metadata from
exchange.py and obtains it from the new source.
The effect of this patch is that once a new compression engine is
registered with util.compengines, `hg bundle -t <engine>` will just
work.
--- a/mercurial/exchange.py Thu Nov 10 23:29:01 2016 -0800
+++ b/mercurial/exchange.py Thu Nov 10 23:34:15 2016 -0800
@@ -37,12 +37,6 @@
urlerr = util.urlerr
urlreq = util.urlreq
-# Maps bundle compression human names to internal representation.
-_bundlespeccompressions = {'none': None,
- 'bzip2': 'BZ',
- 'gzip': 'GZ',
- }
-
# Maps bundle version human names to changegroup versions.
_bundlespeccgversions = {'v1': '01',
'v2': '02',
@@ -114,7 +108,7 @@
if '-' in spec:
compression, version = spec.split('-', 1)
- if compression not in _bundlespeccompressions:
+ if compression not in util.compengines.supportedbundlenames:
raise error.UnsupportedBundleSpecification(
_('%s compression is not supported') % compression)
@@ -130,7 +124,7 @@
spec, params = parseparams(spec)
- if spec in _bundlespeccompressions:
+ if spec in util.compengines.supportedbundlenames:
compression = spec
version = 'v1'
if 'generaldelta' in repo.requirements:
@@ -157,7 +151,8 @@
', '.join(sorted(missingreqs)))
if not externalnames:
- compression = _bundlespeccompressions[compression]
+ engine = util.compengines.forbundlename(compression)
+ compression = engine.bundletype()[1]
version = _bundlespeccgversions[version]
return compression, version, params
@@ -196,10 +191,10 @@
restored.
"""
def speccompression(alg):
- for k, v in _bundlespeccompressions.items():
- if v == alg:
- return k
- return None
+ try:
+ return util.compengines.forbundletype(alg).bundletype()[0]
+ except KeyError:
+ return None
b = readbundle(ui, fh, None)
if isinstance(b, changegroup.cg1unpacker):