changeset 50519:3c0da0fa0eed

stream-clone: check the version of streaming clone supported by the client Make the server refuse to produce streaming clone bundle, if the client doesn't specify the stream=v2 capability. This is in preparation to introduce stream=v3. As far as I can tell, this capability was added at the same time as support for bundle2-based streaming pulls was added, so I don't expect clients to break. (the modern client doesn't break, at any rate)
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Sun, 21 May 2023 00:00:57 +0200
parents f2bcb56a1d39
children 0558866957fa
files mercurial/bundle2.py tests/test-clone-stream.t
diffstat 2 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Sun May 21 01:03:19 2023 +0200
+++ b/mercurial/bundle2.py	Sun May 21 00:00:57 2023 +0200
@@ -1886,6 +1886,14 @@
         msg = _(b'stream data requested but server does not allow this feature')
         hint = _(b'the client seems buggy')
         raise error.Abort(msg, hint=hint)
+    if not (b'stream' in bundler.capabilities):
+        msg = _(
+            b'stream data requested but supported streaming clone versions were not specified'
+        )
+        hint = _(b'the client seems buggy')
+        raise error.Abort(msg, hint=hint)
+    if not (b'v2' in bundler.capabilities[b'stream']):
+        raise error.Abort(_(b'the client does not support streamclone v2'))
 
     # Stream clones don't compress well. And compression undermines a
     # goal of stream clones, which is to be fast. Communicate the desire
--- a/tests/test-clone-stream.t	Sun May 21 01:03:19 2023 +0200
+++ b/tests/test-clone-stream.t	Sun May 21 00:00:57 2023 +0200
@@ -286,7 +286,7 @@
 
 getbundle requests with stream=1 are uncompressed
 
-  $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=getbundle' content-type --bodyfile body --hgproto '0.1 0.2 comp=zlib,none' --requestheader "x-hgarg-1=bundlecaps=HG20%2Cbundle2%3DHG20%250Abookmarks%250Achangegroup%253D01%252C02%252C03%250Adigests%253Dmd5%252Csha1%252Csha512%250Aerror%253Dabort%252Cunsupportedcontent%252Cpushraced%252Cpushkey%250Ahgtagsfnodes%250Alistkeys%250Aphases%253Dheads%250Apushkey%250Aremote-changegroup%253Dhttp%252Chttps&cg=0&common=0000000000000000000000000000000000000000&heads=c17445101a72edac06facd130d14808dfbd5c7c2&stream=1"
+  $ get-with-headers.py $LOCALIP:$HGPORT '?cmd=getbundle' content-type --bodyfile body --hgproto '0.1 0.2 comp=zlib,none' --requestheader "x-hgarg-1=bundlecaps=HG20%2Cbundle2%3DHG20%250Abookmarks%250Achangegroup%253D01%252C02%252C03%250Adigests%253Dmd5%252Csha1%252Csha512%250Aerror%253Dabort%252Cunsupportedcontent%252Cpushraced%252Cpushkey%250Ahgtagsfnodes%250Alistkeys%250Aphases%253Dheads%250Apushkey%250Aremote-changegroup%253Dhttp%252Chttps%250Astream%253Dv2&cg=0&common=0000000000000000000000000000000000000000&heads=c17445101a72edac06facd130d14808dfbd5c7c2&stream=1"
   200 Script output follows
   content-type: application/mercurial-0.2