changeset 50567:f4a540c203d7

stream-clone: support streamv3 on the cli [hg bundle] We add support and test for this. The support is still experimental, so the various name and identifier will eventually need to be renamed when stream-v3 gets out of experimental.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Tue, 23 May 2023 01:39:47 +0200
parents 116da6bb7e3b
children 057639af827c
files mercurial/bundle2.py mercurial/bundlecaches.py mercurial/exchange.py tests/test-stream-bundle-v2.t
diffstat 4 files changed, 62 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue May 23 01:28:56 2023 +0200
+++ b/mercurial/bundle2.py	Tue May 23 01:39:47 2023 +0200
@@ -1736,6 +1736,8 @@
         caps[b'obsmarkers'] = (b'V1',)
     if opts.get(b'streamv2'):
         caps[b'stream'] = [b'v2']
+    elif opts.get(b'streamv3-exp'):
+        caps[b'stream'] = [b'v3-exp']
     bundle = bundle20(ui, caps)
     bundle.setcompression(compression, compopts)
     _addpartsfromopts(ui, repo, bundle, source, outgoing, opts)
@@ -1781,6 +1783,9 @@
     if opts.get(b'streamv2', False):
         addpartbundlestream2(bundler, repo, stream=True)
 
+    if opts.get(b'streamv3-exp', False):
+        addpartbundlestream2(bundler, repo, stream=True)
+
     if opts.get(b'tagsfnodescache', True):
         addparttagsfnodescache(repo, bundler, outgoing)
 
--- a/mercurial/bundlecaches.py	Tue May 23 01:28:56 2023 +0200
+++ b/mercurial/bundlecaches.py	Tue May 23 01:39:47 2023 +0200
@@ -100,6 +100,15 @@
         b'tagsfnodescache': False,
         b'revbranchcache': False,
     },
+    b'streamv3-exp': {
+        b'changegroup': False,
+        b'cg.version': b'03',
+        b'obsolescence': False,
+        b'phases': False,
+        b"streamv3-exp": True,
+        b'tagsfnodescache': False,
+        b'revbranchcache': False,
+    },
     b'packed1': {
         b'cg.version': b's1',
     },
@@ -278,8 +287,10 @@
         # warning when the old way is encountered)
         if params[b"stream"] == b"v2":
             version = b"streamv2"
+        if params[b"stream"] == b"v3-exp":
+            version = b"streamv3-exp"
     contentopts = _bundlespeccontentopts.get(version, {}).copy()
-    if version == b"streamv2":
+    if version == b"streamv2" or version == b"streamv3-exp":
         # streamv2 have been reported as "v2" for a while.
         version = b"v2"
 
@@ -337,7 +348,10 @@
     if (
         bundlespec.wirecompression == b'UN'
         and bundlespec.wireversion == b'02'
-        and bundlespec.contentopts.get(b'streamv2')
+        and (
+            bundlespec.contentopts.get(b'streamv2')
+            or bundlespec.contentopts.get(b'streamv3-exp')
+        )
     ):
         return True
 
--- a/mercurial/exchange.py	Tue May 23 01:28:56 2023 +0200
+++ b/mercurial/exchange.py	Tue May 23 01:39:47 2023 +0200
@@ -146,6 +146,12 @@
                 splitted = requirements.split()
                 params = bundle2._formatrequirementsparams(splitted)
                 return b'none-v2;stream=v2;%s' % params
+            elif part.type == b'stream3-exp' and version is None:
+                # A stream3 part requires to be part of a v2 bundle
+                requirements = urlreq.unquote(part.params[b'requirements'])
+                splitted = requirements.split()
+                params = bundle2._formatrequirementsparams(splitted)
+                return b'none-v2;stream=v3-exp;%s' % params
             elif part.type == b'obsmarkers':
                 params[b'obsolescence'] = b'yes'
                 if not part.mandatory:
--- a/tests/test-stream-bundle-v2.t	Tue May 23 01:28:56 2023 +0200
+++ b/tests/test-stream-bundle-v2.t	Tue May 23 01:39:47 2023 +0200
@@ -1,6 +1,21 @@
 #require no-reposimplestore
 
-Test creating a consuming stream bundle v2
+#testcases stream-v2 stream-v3
+
+#if stream-v2
+  $ bundle_format="streamv2"
+  $ stream_version="v2"
+#endif
+#if stream-v3
+  $ bundle_format="streamv3-exp"
+  $ stream_version="v3-exp"
+  $ cat << EOF >> $HGRCPATH
+  > [experimental]
+  > stream-v3=yes
+  > EOF
+#endif
+
+Test creating a consuming stream bundle v2 and v3
 
   $ getmainid() {
   >    hg -R main log --template '{node}\n' --rev "$1"
@@ -42,16 +57,22 @@
   > A
   > EOF
 
-  $ hg bundle -a --type="none-v2;stream=v2" bundle.hg
+  $ hg bundle -a --type="none-v2;stream=$stream_version" bundle.hg
   $ hg debugbundle bundle.hg
   Stream params: {}
-  stream2 -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlogv1%2Csparserevlog} (mandatory: True) (no-zstd !)
-  stream2 -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog} (mandatory: True) (zstd no-rust !)
-  stream2 -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog} (mandatory: True) (rust !)
+  stream2 -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlogv1%2Csparserevlog} (mandatory: True) (stream-v2 no-zstd !)
+  stream2 -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog} (mandatory: True) (stream-v2 zstd no-rust !)
+  stream2 -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog} (mandatory: True) (stream-v2 rust !)
+  stream3-exp -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlogv1%2Csparserevlog} (mandatory: True) (stream-v3 no-zstd !)
+  stream3-exp -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog} (mandatory: True) (stream-v3 zstd no-rust !)
+  stream3-exp -- {bytecount: 1693, filecount: 11, requirements: generaldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog} (mandatory: True) (stream-v3 rust !)
   $ hg debugbundle --spec bundle.hg
-  none-v2;stream=v2;requirements%3Dgeneraldelta%2Crevlogv1%2Csparserevlog (no-zstd !)
-  none-v2;stream=v2;requirements%3Dgeneraldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog (zstd no-rust !)
-  none-v2;stream=v2;requirements%3Dgeneraldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog (rust !)
+  none-v2;stream=v2;requirements%3Dgeneraldelta%2Crevlogv1%2Csparserevlog (stream-v2 no-zstd !)
+  none-v2;stream=v2;requirements%3Dgeneraldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog (stream-v2 zstd no-rust !)
+  none-v2;stream=v2;requirements%3Dgeneraldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog (stream-v2 rust !)
+  none-v2;stream=v3-exp;requirements%3Dgeneraldelta%2Crevlogv1%2Csparserevlog (stream-v3 no-zstd !)
+  none-v2;stream=v3-exp;requirements%3Dgeneraldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog (stream-v3 zstd no-rust !)
+  none-v2;stream=v3-exp;requirements%3Dgeneraldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog (stream-v3 rust !)
 
 Test that we can apply the bundle as a stream clone bundle
 
@@ -66,13 +87,14 @@
   $ cat http.pid >> $DAEMON_PIDS
 
   $ cd ..
-  $ hg clone http://localhost:$HGPORT streamv2-clone-implicit --debug
+  $ hg clone http://localhost:$HGPORT stream-clone-implicit --debug
   using http://localhost:$HGPORT/
   sending capabilities command
   sending clonebundles command
   applying clone bundle from http://localhost:$HGPORT1/bundle.hg
   bundle2-input-bundle: with-transaction
-  bundle2-input-part: "stream2" (params: 3 mandatory) supported
+  bundle2-input-part: "stream2" (params: 3 mandatory) supported (stream-v2 !)
+  bundle2-input-part: "stream3-exp" (params: 3 mandatory) supported (stream-v3 !)
   applying stream bundle
   11 files to transfer, 1.65 KB of data
   starting 4 threads for background file closing (?)
@@ -123,13 +145,14 @@
   updating the branch cache
   (sent 4 HTTP requests and * bytes; received * bytes in responses) (glob)
 
-  $ hg clone --stream http://localhost:$HGPORT streamv2-clone-explicit --debug
+  $ hg clone --stream http://localhost:$HGPORT stream-clone-explicit --debug
   using http://localhost:$HGPORT/
   sending capabilities command
   sending clonebundles command
   applying clone bundle from http://localhost:$HGPORT1/bundle.hg
   bundle2-input-bundle: with-transaction
-  bundle2-input-part: "stream2" (params: 3 mandatory) supported
+  bundle2-input-part: "stream2" (params: 3 mandatory) supported (stream-v2 !)
+  bundle2-input-part: "stream3-exp" (params: 3 mandatory) supported (stream-v3 !)
   applying stream bundle
   11 files to transfer, 1.65 KB of data
   starting 4 threads for background file closing (?)