Mercurial > hg
comparison mercurial/exchange.py @ 30440:c3944ab1443a
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 10 Nov 2016 23:34:15 -0800 |
parents | 318a24b52eeb |
children | 8491845a75b2 |
comparison
equal
deleted
inserted
replaced
30439:71b368e3b590 | 30440:c3944ab1443a |
---|---|
35 ) | 35 ) |
36 | 36 |
37 urlerr = util.urlerr | 37 urlerr = util.urlerr |
38 urlreq = util.urlreq | 38 urlreq = util.urlreq |
39 | 39 |
40 # Maps bundle compression human names to internal representation. | |
41 _bundlespeccompressions = {'none': None, | |
42 'bzip2': 'BZ', | |
43 'gzip': 'GZ', | |
44 } | |
45 | |
46 # Maps bundle version human names to changegroup versions. | 40 # Maps bundle version human names to changegroup versions. |
47 _bundlespeccgversions = {'v1': '01', | 41 _bundlespeccgversions = {'v1': '01', |
48 'v2': '02', | 42 'v2': '02', |
49 'packed1': 's1', | 43 'packed1': 's1', |
50 'bundle2': '02', #legacy | 44 'bundle2': '02', #legacy |
112 'must be prefixed with compression: %s') % spec) | 106 'must be prefixed with compression: %s') % spec) |
113 | 107 |
114 if '-' in spec: | 108 if '-' in spec: |
115 compression, version = spec.split('-', 1) | 109 compression, version = spec.split('-', 1) |
116 | 110 |
117 if compression not in _bundlespeccompressions: | 111 if compression not in util.compengines.supportedbundlenames: |
118 raise error.UnsupportedBundleSpecification( | 112 raise error.UnsupportedBundleSpecification( |
119 _('%s compression is not supported') % compression) | 113 _('%s compression is not supported') % compression) |
120 | 114 |
121 version, params = parseparams(version) | 115 version, params = parseparams(version) |
122 | 116 |
128 # case some defaults are assumed (but only when not in strict mode). | 122 # case some defaults are assumed (but only when not in strict mode). |
129 assert not strict | 123 assert not strict |
130 | 124 |
131 spec, params = parseparams(spec) | 125 spec, params = parseparams(spec) |
132 | 126 |
133 if spec in _bundlespeccompressions: | 127 if spec in util.compengines.supportedbundlenames: |
134 compression = spec | 128 compression = spec |
135 version = 'v1' | 129 version = 'v1' |
136 if 'generaldelta' in repo.requirements: | 130 if 'generaldelta' in repo.requirements: |
137 version = 'v2' | 131 version = 'v2' |
138 elif spec in _bundlespeccgversions: | 132 elif spec in _bundlespeccgversions: |
155 raise error.UnsupportedBundleSpecification( | 149 raise error.UnsupportedBundleSpecification( |
156 _('missing support for repository features: %s') % | 150 _('missing support for repository features: %s') % |
157 ', '.join(sorted(missingreqs))) | 151 ', '.join(sorted(missingreqs))) |
158 | 152 |
159 if not externalnames: | 153 if not externalnames: |
160 compression = _bundlespeccompressions[compression] | 154 engine = util.compengines.forbundlename(compression) |
155 compression = engine.bundletype()[1] | |
161 version = _bundlespeccgversions[version] | 156 version = _bundlespeccgversions[version] |
162 return compression, version, params | 157 return compression, version, params |
163 | 158 |
164 def readbundle(ui, fh, fname, vfs=None): | 159 def readbundle(ui, fh, fname, vfs=None): |
165 header = changegroup.readexactly(fh, 4) | 160 header = changegroup.readexactly(fh, 4) |
194 | 189 |
195 The input file handle is seeked and the original seek position is not | 190 The input file handle is seeked and the original seek position is not |
196 restored. | 191 restored. |
197 """ | 192 """ |
198 def speccompression(alg): | 193 def speccompression(alg): |
199 for k, v in _bundlespeccompressions.items(): | 194 try: |
200 if v == alg: | 195 return util.compengines.forbundletype(alg).bundletype()[0] |
201 return k | 196 except KeyError: |
202 return None | 197 return None |
203 | 198 |
204 b = readbundle(ui, fh, None) | 199 b = readbundle(ui, fh, None) |
205 if isinstance(b, changegroup.cg1unpacker): | 200 if isinstance(b, changegroup.cg1unpacker): |
206 alg = b._type | 201 alg = b._type |
207 if alg == '_truncatedBZ': | 202 if alg == '_truncatedBZ': |