# HG changeset patch # User Pierre-Yves David # Date 1428361473 25200 # Node ID 60fecc5b14a45de49af875087c0a0e3b2820c7af # Parent 685639f9430d407fbb3f35a09ca694c76bc10170 unbundle20: retrieve unbundler instances through a factory function To support multiple bundle2 formats, we will need a function returning the proper unbundler according to the header. We introduce such aa function and change the usage in the code base. The function will get smarter in later changesets. This is somewhat similar to the dispatching we do for 'HG10' and 'HG11'. The main target is to allow HG2Y support in an extension to ease transition of companies using the experimental protocol in production (yeah...) But I've no doubt this will be useful when playing with a future HG21. diff -r 685639f9430d -r 60fecc5b14a4 mercurial/bundle2.py --- a/mercurial/bundle2.py Mon Apr 06 15:40:12 2015 -0700 +++ b/mercurial/bundle2.py Mon Apr 06 16:04:33 2015 -0700 @@ -521,6 +521,10 @@ if util.safehasattr(self._fp, 'close'): return self._fp.close() +def getunbundler(ui, fp, header=None): + """return a valid unbundler object for a given header""" + return unbundle20(ui, fp, header) + class unbundle20(unpackermixin): """interpret a bundle2 stream diff -r 685639f9430d -r 60fecc5b14a4 mercurial/exchange.py --- a/mercurial/exchange.py Mon Apr 06 15:40:12 2015 -0700 +++ b/mercurial/exchange.py Mon Apr 06 16:04:33 2015 -0700 @@ -33,7 +33,7 @@ alg = changegroup.readexactly(fh, 2) return changegroup.cg1unpacker(fh, alg) elif version == '2Y': - return bundle2.unbundle20(ui, fh, header=magic + version) + return bundle2.getunbundler(ui, fh, header=magic + version) else: raise util.Abort(_('%s: unknown bundle version %s') % (fname, version)) diff -r 685639f9430d -r 60fecc5b14a4 mercurial/localrepo.py --- a/mercurial/localrepo.py Mon Apr 06 15:40:12 2015 -0700 +++ b/mercurial/localrepo.py Mon Apr 06 16:04:33 2015 -0700 @@ -114,7 +114,7 @@ # When requesting a bundle2, getbundle returns a stream to make the # wire level function happier. We need to build a proper object # from it in local peer. - cg = bundle2.unbundle20(self.ui, cg) + cg = bundle2.getunbundler(self.ui, cg) return cg # TODO We might want to move the next two calls into legacypeer and add @@ -132,7 +132,7 @@ # This little dance should be dropped eventually when the API # is finally improved. stream = util.chunkbuffer(ret.getchunks()) - ret = bundle2.unbundle20(self.ui, stream) + ret = bundle2.getunbundler(self.ui, stream) return ret except error.PushRaced, exc: raise error.ResponseError(_('push failed:'), str(exc)) diff -r 685639f9430d -r 60fecc5b14a4 mercurial/wireproto.py --- a/mercurial/wireproto.py Mon Apr 06 15:40:12 2015 -0700 +++ b/mercurial/wireproto.py Mon Apr 06 16:04:33 2015 -0700 @@ -364,7 +364,7 @@ f = self._callcompressable("getbundle", **opts) bundlecaps = kwargs.get('bundlecaps') if bundlecaps is not None and 'HG2Y' in bundlecaps: - return bundle2.unbundle20(self.ui, f) + return bundle2.getunbundler(self.ui, f) else: return changegroupmod.cg1unpacker(f, 'UN') @@ -401,7 +401,7 @@ else: # bundle2 push. Send a stream, fetch a stream. stream = self._calltwowaystream('unbundle', cg, heads=heads) - ret = bundle2.unbundle20(self.ui, stream) + ret = bundle2.getunbundler(self.ui, stream) return ret def debugwireargs(self, one, two, three=None, four=None, five=None): diff -r 685639f9430d -r 60fecc5b14a4 tests/test-bundle2-format.t --- a/tests/test-bundle2-format.t Mon Apr 06 15:40:12 2015 -0700 +++ b/tests/test-bundle2-format.t Mon Apr 06 16:04:33 2015 -0700 @@ -157,7 +157,7 @@ > lock = repo.lock() > tr = repo.transaction('processbundle') > try: - > unbundler = bundle2.unbundle20(ui, sys.stdin) + > unbundler = bundle2.getunbundler(ui, sys.stdin) > op = bundle2.processbundle(repo, unbundler, lambda: tr) > tr.close() > except error.BundleValueError, exc: @@ -183,7 +183,7 @@ > @command('statbundle2', [], '') > def cmdstatbundle2(ui, repo): > """print statistic on the bundle2 container read from stdin""" - > unbundler = bundle2.unbundle20(ui, sys.stdin) + > unbundler = bundle2.getunbundler(ui, sys.stdin) > try: > params = unbundler.params > except error.BundleValueError, exc: