Patchwork [2,of,9] bundle2: rename the _canusebundle2 method to _forcebundle1

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 3, 2016, 2:54 p.m.
Message ID <2d61469ee8d3af037aa4.1470236087@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16058/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 3, 2016, 2:54 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1470229283 -7200
#      Wed Aug 03 15:01:23 2016 +0200
# Node ID 2d61469ee8d3af037aa4e2730576777bbe12ff57
# Parent  cba97bcff849b3d366ca56f597efa7ccc6df458a
# EXP-Topic bundle2.devel
bundle2: rename the _canusebundle2 method to _forcebundle1

We rename and invert the logic of the _canusebundle2 utility. The idea here is
that we need to have a way to enforce the use of bundle1 in the tests. The
Mercurial philosophy is to try to use the best method available. Currently that
best method is bundle2, but this might change in the future. Therefore expressing
"do not use bundle2" is a loosy way to say "use bundle 1" and will likely create
issue in the future. As the config option will be explicitly about bundle1, we
rename the function beforehand to align with this. This will make the life of a
future developer working on bundle3 easier.
Yuya Nishihara - Aug. 4, 2016, 2:22 p.m.
On Wed, 03 Aug 2016 16:54:47 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1470229283 -7200
> #      Wed Aug 03 15:01:23 2016 +0200
> # Node ID 2d61469ee8d3af037aa4e2730576777bbe12ff57
> # Parent  cba97bcff849b3d366ca56f597efa7ccc6df458a
> # EXP-Topic bundle2.devel
> bundle2: rename the _canusebundle2 method to _forcebundle1

> --- a/mercurial/exchange.py	Wed Aug 03 14:24:09 2016 +0200
> +++ b/mercurial/exchange.py	Wed Aug 03 15:01:23 2016 +0200
> @@ -257,12 +257,12 @@ def buildobsmarkerspart(bundler, markers
>          return bundler.newpart('obsmarkers', data=stream)
>      return None
>  
> -def _canusebundle2(op):
> +def _forcebundle1(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', True)
> -            and op.remote.capable('bundle2'))
> +    return not (op.repo.ui.configbool('experimental', 'bundle2-exp', True)
> +                and op.remote.capable('bundle2'))

Updated the docstring as s/can use bundle2/must use bundle1/.

Patch

diff -r cba97bcff849 -r 2d61469ee8d3 mercurial/exchange.py
--- a/mercurial/exchange.py	Wed Aug 03 14:24:09 2016 +0200
+++ b/mercurial/exchange.py	Wed Aug 03 15:01:23 2016 +0200
@@ -257,12 +257,12 @@  def buildobsmarkerspart(bundler, markers
         return bundler.newpart('obsmarkers', data=stream)
     return None
 
-def _canusebundle2(op):
+def _forcebundle1(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', True)
-            and op.remote.capable('bundle2'))
+    return not (op.repo.ui.configbool('experimental', 'bundle2-exp', True)
+                and op.remote.capable('bundle2'))
 
 
 class pushoperation(object):
@@ -417,7 +417,7 @@  def push(repo, remote, force=False, revs
         # bundle2 push may receive a reply bundle touching bookmarks or other
         # things requiring the wlock. Take it now to ensure proper ordering.
         maypushback = pushop.ui.configbool('experimental', 'bundle2.pushback')
-        if _canusebundle2(pushop) and maypushback:
+        if (not _forcebundle1(pushop)) and maypushback:
             localwlock = pushop.repo.wlock()
         locallock = pushop.repo.lock()
         pushop.locallocked = True
@@ -442,7 +442,7 @@  def push(repo, remote, force=False, revs
             lock = pushop.remote.lock()
         try:
             _pushdiscovery(pushop)
-            if _canusebundle2(pushop):
+            if not _forcebundle1(pushop):
                 _pushbundle2(pushop)
             _pushchangeset(pushop)
             _pushsyncphase(pushop)
@@ -1099,7 +1099,7 @@  class pulloperation(object):
 
     @util.propertycache
     def canusebundle2(self):
-        return _canusebundle2(self)
+        return not _forcebundle1(self)
 
     @util.propertycache
     def remotebundle2caps(self):