# HG changeset patch # User Martin von Zweigbergk # Date 2016-01-13 05:01:06 # Node ID a40e2f7fe49db96c61e2d47866cdd99200297151 # Parent 443848eece189002c542339dc1cf84f49a94c824 changegroup: hide packermap behind methods This is to prepare for hiding changegroup3 behind a config option. diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -1240,7 +1240,7 @@ def getrepocaps(repo, allowpushback=Fals Exists to allow extensions (like evolution) to mutate the capabilities. """ caps = capabilities.copy() - caps['changegroup'] = tuple(sorted(changegroup.packermap.keys())) + caps['changegroup'] = tuple(sorted(changegroup.supportedversions(repo))) if obsolete.isenabled(repo, obsolete.exchangeopt): supportedformat = tuple('V%i' % v for v in obsolete.formats) caps['obsmarkers'] = supportedformat @@ -1277,8 +1277,7 @@ def handlechangegroup(op, inpart): op.gettransaction() unpackerversion = inpart.params.get('version', '01') # We should raise an appropriate exception here - unpacker = changegroup.packermap[unpackerversion][1] - cg = unpacker(inpart, None) + cg = changegroup.getunbundler(unpackerversion, inpart, None) # the source and url passed here are overwritten by the one contained in # the transaction.hookargs argument. So 'bundle2' is a placeholder nbchangesets = None diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py +++ b/mercurial/bundlerepo.py @@ -285,7 +285,7 @@ class bundlerepository(localrepo.localre "multiple changegroups") cgstream = part version = part.params.get('version', '01') - if version not in changegroup.packermap: + if version not in changegroup.supportedversions(self): msg = _('Unsupported changegroup version: %s') raise error.Abort(msg % version) if self.bundle.compressed(): @@ -296,7 +296,7 @@ class bundlerepository(localrepo.localre raise error.Abort('No changegroups found') cgstream.seek(0) - self.bundle = changegroup.packermap[version][1](cgstream, 'UN') + self.bundle = changegroup.getunbundler(version, cgstream, 'UN') elif self.bundle.compressed(): f = _writetempbundle(self.bundle.read, '.hg10un', header='HG10UN') diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -914,13 +914,23 @@ class cg3packer(cg2packer): return struct.pack( self.deltaheader, node, p1n, p2n, basenode, linknode, flags) -packermap = {'01': (cg1packer, cg1unpacker), +_packermap = {'01': (cg1packer, cg1unpacker), # cg2 adds support for exchanging generaldelta '02': (cg2packer, cg2unpacker), # cg3 adds support for exchanging treemanifests '03': (cg3packer, cg3unpacker), } +def supportedversions(repo): + return _packermap.keys() + +def getbundler(version, repo, bundlecaps=None): + assert version in supportedversions(repo) + return _packermap[version][0](repo, bundlecaps) + +def getunbundler(version, fh, alg): + return _packermap[version][1](fh, alg) + def _changegroupinfo(repo, nodes, source): if repo.ui.verbose or source == 'bundle': repo.ui.status(_("%d changesets found\n") % len(nodes)) @@ -947,7 +957,7 @@ def getsubsetraw(repo, outgoing, bundler def getsubset(repo, outgoing, bundler, source, fastpath=False): gengroup = getsubsetraw(repo, outgoing, bundler, source, fastpath) - return packermap[bundler.version][1](util.chunkbuffer(gengroup), None) + return getunbundler(bundler.version, util.chunkbuffer(gengroup), None) def changegroupsubset(repo, roots, heads, source, version='01'): """Compute a changegroup consisting of all the nodes that are @@ -973,7 +983,7 @@ def changegroupsubset(repo, roots, heads included = set(csets) discbases = [n for n in discbases if n not in included] outgoing = discovery.outgoing(cl, discbases, heads) - bundler = packermap[version][0](repo) + bundler = getbundler(version, repo) return getsubset(repo, outgoing, bundler, source) def getlocalchangegroupraw(repo, source, outgoing, bundlecaps=None, @@ -984,7 +994,7 @@ def getlocalchangegroupraw(repo, source, precomputed sets in outgoing. Returns a raw changegroup generator.""" if not outgoing.missing: return None - bundler = packermap[version][0](repo, bundlecaps) + bundler = getbundler(version, repo, bundlecaps) return getsubsetraw(repo, outgoing, bundler, source) def getlocalchangegroup(repo, source, outgoing, bundlecaps=None, @@ -995,7 +1005,7 @@ def getlocalchangegroup(repo, source, ou precomputed sets in outgoing.""" if not outgoing.missing: return None - bundler = packermap[version][0](repo, bundlecaps) + bundler = getbundler(version, repo, bundlecaps) return getsubset(repo, outgoing, bundler, source) def computeoutgoing(repo, heads, common): diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2078,7 +2078,7 @@ def _debugbundle2(ui, gen, **opts): ui.write('%s -- %r\n' % (part.type, repr(part.params))) if part.type == 'changegroup': version = part.params.get('version', '01') - cg = changegroup.packermap[version][1](part, 'UN') + cg = changegroup.getunbundler(version, part, 'UN') chunkdata = cg.changelogheader() chain = None while True: diff --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -653,7 +653,8 @@ def _pushb2ctx(pushop, bundler): cg = changegroup.getlocalchangegroupraw(pushop.repo, 'push', pushop.outgoing) else: - cgversions = [v for v in cgversions if v in changegroup.packermap] + cgversions = [v for v in cgversions + if v in changegroup.supportedversions(pushop.repo)] if not cgversions: raise ValueError(_('no common changegroup version')) version = max(cgversions) @@ -1505,7 +1506,8 @@ def _getbundlechangegrouppart(bundler, r cgversions = b2caps.get('changegroup') getcgkwargs = {} if cgversions: # 3.1 and 3.2 ship with an empty value - cgversions = [v for v in cgversions if v in changegroup.packermap] + cgversions = [v for v in cgversions + if v in changegroup.supportedversions(repo)] if not cgversions: raise ValueError(_('no common changegroup version')) version = getcgkwargs['version'] = max(cgversions)