diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -521,6 +521,10 @@ class unpackermixin(object): 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 --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -33,7 +33,7 @@ def readbundle(ui, fh, fname, vfs=None): 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 --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -114,7 +114,7 @@ class localpeer(peer.peerrepository): # 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 @@ class localpeer(peer.peerrepository): # 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 --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -364,7 +364,7 @@ class wirepeer(peer.peerrepository): 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 @@ class wirepeer(peer.peerrepository): 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 --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t --- a/tests/test-bundle2-format.t +++ b/tests/test-bundle2-format.t @@ -157,7 +157,7 @@ Create an extension to test bundle2 API > 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 @@ Create an extension to test bundle2 API > @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: