Mercurial > public > mercurial-scm > hg-stable
diff mercurial/exchange.py @ 20955:12f161f08d74
bundle2: allow pulling changegroups using bundle2
This changeset refactors the pull code to use a bundle2 when available. We keep
bundle2 disabled by default. The current code is not ready for prime time.
Ultimately we'll want to unify the API of `bunde10` and `bundle20` to have less
different code. But for now, testing the bundle2 exchange flow is an higher
priority.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 01 Apr 2014 23:41:32 -0700 |
parents | dba91f8060eb |
children | dbf0fa39a5b8 |
line wrap: on
line diff
--- a/mercurial/exchange.py Fri Apr 04 01:51:54 2014 -0700 +++ b/mercurial/exchange.py Tue Apr 01 23:41:32 2014 -0700 @@ -7,9 +7,10 @@ from i18n import _ from node import hex, nullid +import cStringIO import errno import util, scmutil, changegroup, base85 -import discovery, phases, obsolete, bookmarks +import discovery, phases, obsolete, bookmarks, bundle2 class pushoperation(object): @@ -455,6 +456,8 @@ lock = pullop.repo.lock() try: _pulldiscovery(pullop) + if pullop.remote.capable('bundle2'): + _pullbundle2(pullop) if 'changegroup' in pullop.todosteps: _pullchangeset(pullop) if 'phases' in pullop.todosteps: @@ -479,6 +482,31 @@ force=pullop.force) pullop.common, pullop.fetch, pullop.rheads = tmp +def _pullbundle2(pullop): + """pull data using bundle2 + + For now, the only supported data are changegroup.""" + kwargs = {'bundlecaps': set(['HG20'])} + # pulling changegroup + pullop.todosteps.remove('changegroup') + if not pullop.fetch: + pullop.repo.ui.status(_("no changes found\n")) + pullop.cgresult = 0 + else: + kwargs['common'] = pullop.common + kwargs['heads'] = pullop.heads or pullop.rheads + if pullop.heads is None and list(pullop.common) == [nullid]: + pullop.repo.ui.status(_("requesting all changes\n")) + if kwargs.keys() == ['format']: + return # nothing to pull + bundle = pullop.remote.getbundle('pull', **kwargs) + try: + op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction) + except KeyError, exc: + raise util.Abort('missing support for %s' % exc) + assert len(op.records['changegroup']) == 1 + pullop.cgresult = op.records['changegroup'][0]['return'] + def _pullchangeset(pullop): """pull changeset from unbundle into the local repo""" # We delay the open of the transaction as late as possible so we