From patchwork Fri Nov 11 09:23:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6,of,8] exchange: obtain compression engines from the registrar From: Gregory Szorc X-Patchwork-Id: 17473 Message-Id: <45801e65f33949e6663e.1478856218@ubuntu-vm-main> To: mercurial-devel@mercurial-scm.org Date: Fri, 11 Nov 2016 01:23:38 -0800 # HG changeset patch # User Gregory Szorc # Date 1478849655 28800 # Thu Nov 10 23:34:15 2016 -0800 # Node ID 45801e65f33949e6663ebfff651cb78d01afcc3e # Parent 0239a4e94147ce85aecb71bfb0dbf227410a7b67 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 ` will just work. diff --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -37,12 +37,6 @@ from . import ( 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 @@ def parsebundlespec(repo, spec, strict=T 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 @@ def parsebundlespec(repo, spec, strict=T 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 @@ def parsebundlespec(repo, spec, strict=T ', '.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 @@ def getbundlespec(ui, fh): 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):