exchange: introduce a '_canusebundle2' function
This function refactors the logic that decides to use 'bundle2' during an
exchange (pull/push). This will help being consistent while transitioning from
the experimental protocol to the final frozen version.
I do not expect this function to survive on the long run when using 'bundle2'
will become a simple capability check.
This is also necessary to allow HG2Y support in an extension to ease transition
of companies using the experimental protocol in production (yeah...). Such
extension will be able to wrap this function to use the experimental protocol in
some case.
--- a/mercurial/exchange.py Tue Apr 07 16:01:32 2015 -0700
+++ b/mercurial/exchange.py Mon Apr 06 18:31:59 2015 -0700
@@ -52,6 +52,14 @@
return bundler.newpart('b2x:obsmarkers', data=stream)
return None
+def _canusebundle2(op):
+ """return true if a pull/push can use bundle2
+
+ Feel free to nuke this function when we drop the experimental option"""
+ return (op.repo.ui.configbool('experimental', 'bundle2-exp', False)
+ and op.remote.capable('bundle2-exp'))
+
+
class pushoperation(object):
"""A object that represent a single push operation
@@ -217,9 +225,7 @@
lock = pushop.remote.lock()
try:
_pushdiscovery(pushop)
- if (pushop.repo.ui.configbool('experimental', 'bundle2-exp',
- False)
- and pushop.remote.capable('bundle2-exp')):
+ if _canusebundle2(pushop):
_pushbundle2(pushop)
_pushchangeset(pushop)
_pushsyncphase(pushop)
@@ -876,8 +882,7 @@
try:
pullop.trmanager = transactionmanager(repo, 'pull', remote.url())
_pulldiscovery(pullop)
- if (pullop.repo.ui.configbool('experimental', 'bundle2-exp', False)
- and pullop.remote.capable('bundle2-exp')):
+ if _canusebundle2(pullop):
_pullbundle2(pullop)
_pullchangeset(pullop)
_pullphase(pullop)