bundle2: don't advertise stream bundle2 capability when feature disabled
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 22 Jan 2018 12:21:15 -0800
changeset 41699 c1b9eb15a51c7b1b7ff8334bd47863537e8dccd9
parent 41698 8ed5f7609728f09195ffa580efbc4b5c98444ccf
child 41700 9adae6a20e1f0e9ac69d988fa5e14066a437dde5
push id656
push usergszorc@mozilla.com
push dateTue, 23 Jan 2018 02:05:10 +0000
bundle2: don't advertise stream bundle2 capability when feature disabled The server.uncompressed config option can be used to disable streaming clones. While the top-level capability to advertise streaming clone support isn't advertised when this option is set, we were still sending the bundle2-level capabilities advertising support for stream parts. It makes sense to not advertise that support when streaming clones are globally disabled. If the structure of the new code seems a bit odd, it is because we'll have to further tweak the behavior in commit(s) ahead. Differential Revision: https://phab.mercurial-scm.org/D1929
mercurial/bundle2.py
tests/test-clone-uncompressed.t
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1514,18 +1514,30 @@ def getrepocaps(repo, allowpushback=Fals
         caps['obsmarkers'] = supportedformat
     if allowpushback:
         caps['pushback'] = ()
     cpmode = repo.ui.config('server', 'concurrent-push-mode')
     if cpmode == 'check-related':
         caps['checkheads'] = ('related',)
     if 'phases' in repo.ui.configlist('devel', 'legacy.exchange'):
         caps.pop('phases')
-    if not repo.ui.configbool('experimental', 'bundle2.stream'):
-        caps.pop('stream')
+
+    # Don't advertise stream clone support in server mode if not configured.
+    if role == 'server':
+        streamsupported = repo.ui.configbool('server', 'uncompressed',
+                                             untrusted=True)
+        featuresupported = repo.ui.configbool('experimental', 'bundle2.stream')
+
+        if not streamsupported or not featuresupported:
+            caps.pop('stream')
+    # role == 'client'
+    else:
+        if not repo.ui.configbool('experimental', 'bundle2.stream'):
+            caps.pop('stream')
+
     return caps
 
 def bundle2caps(remote):
     """return the bundle capabilities of a peer as dict"""
     raw = remote.capable('bundle2')
     if not raw and raw != '':
         return {}
     capsblob = urlreq.unquote(remote.capable('bundle2'))
--- a/tests/test-clone-uncompressed.t
+++ b/tests/test-clone-uncompressed.t
@@ -97,17 +97,17 @@ Cannot stream clone when server.uncompre
   0060: 6e 65 72 61                                     |nera|
 
 #endif
 #if stream-bundle2
   $ hg debugcapabilities http://localhost:$HGPORT
   Main capabilities:
     batch
     branchmap
-    $USUAL_BUNDLE2_CAPS$%0Astream%3Dv2
+    $USUAL_BUNDLE2_CAPS$
     changegroupsubset
     compression=zstd,zlib
     getbundle
     httpheader=1024
     httpmediatype=0.1rx,0.1tx,0.2tx
     known
     lookup
     pushkey
@@ -131,18 +131,16 @@ Cannot stream clone when server.uncompre
     hgtagsfnodes
     listkeys
     phases
       heads
     pushkey
     remote-changegroup
       http
       https
-    stream
-      v2
 
   $ hg clone --stream -U http://localhost:$HGPORT server-disabled
   warning: stream clone requested but server has them disabled
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
   added 2 changesets with 1025 changes to 1025 files