[PATCH 6 of 8] exchange: obtain compression engines from the registrar

Gregory Szorc gregory.szorc at gmail.com
Fri Nov 11 09:23:38 UTC 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# 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 <engine>` 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):



More information about the Mercurial-devel mailing list