streamclone: add support for bundle2 based stream clone
authorBoris Feld <boris.feld@octobus.net>
Wed, 17 Jan 2018 16:41:44 +0100
changeset 35763 7eedbd5d4880
parent 35762 40df727b6f4f
child 35764 b6ffd4194639
streamclone: add support for bundle2 based stream clone The feature put to use the various bits introduced previously. If the server supports it, the client will request its stream clone through bundle2 instead of the legacy 'stream_out' commands. The bundle2 version use the better 'v2' version of stream bundles. The 'v2' format is not finalized yet. Now that there are some code running it, we can start working on it again. Performance numbers are available at the end of this series.
mercurial/bundle2.py
mercurial/configitems.py
mercurial/exchange.py
tests/test-clone-uncompressed.t
--- a/mercurial/bundle2.py	Wed Jan 17 14:13:46 2018 +0100
+++ b/mercurial/bundle2.py	Wed Jan 17 16:41:44 2018 +0100
@@ -1487,6 +1487,7 @@
                 'remote-changegroup': ('http', 'https'),
                 'hgtagsfnodes': (),
                 'phases': ('heads',),
+                'stream': ('v2',),
                }
 
 def getrepocaps(repo, allowpushback=False):
@@ -1507,6 +1508,8 @@
         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')
     return caps
 
 def bundle2caps(remote):
--- a/mercurial/configitems.py	Wed Jan 17 14:13:46 2018 +0100
+++ b/mercurial/configitems.py	Wed Jan 17 16:41:44 2018 +0100
@@ -431,6 +431,9 @@
 coreconfigitem('experimental', 'bundle2.pushback',
     default=False,
 )
+coreconfigitem('experimental', 'bundle2.stream',
+    default=False,
+)
 coreconfigitem('experimental', 'bundle2lazylocking',
     default=False,
 )
--- a/mercurial/exchange.py	Wed Jan 17 14:13:46 2018 +0100
+++ b/mercurial/exchange.py	Wed Jan 17 16:41:44 2018 +0100
@@ -1455,13 +1455,18 @@
 
     # At the moment we don't do stream clones over bundle2. If that is
     # implemented then here's where the check for that will go.
-    streaming = False
+    streaming = streamclone.canperformstreamclone(pullop, bundle2=True)[0]
 
     # declare pull perimeters
     kwargs['common'] = pullop.common
     kwargs['heads'] = pullop.heads or pullop.rheads
 
-    if True:
+    if streaming:
+        kwargs['cg'] = False
+        kwargs['stream'] = True
+        pullop.stepsdone.add('changegroup')
+
+    else:
         # pulling changegroup
         pullop.stepsdone.add('changegroup')
 
--- a/tests/test-clone-uncompressed.t	Wed Jan 17 14:13:46 2018 +0100
+++ b/tests/test-clone-uncompressed.t	Wed Jan 17 16:41:44 2018 +0100
@@ -1,5 +1,14 @@
 #require serve
 
+#testcases stream-legacy stream-bundle2
+
+#if stream-bundle2
+  $ cat << EOF >> $HGRCPATH
+  > [experimental]
+  > bundle2.stream = yes
+  > EOF
+#endif
+
 Initialize repository
 the status call is to check for issue5130
 
@@ -18,24 +27,41 @@
 
 Basic clone
 
+#if stream-legacy
   $ hg clone --stream -U http://localhost:$HGPORT clone1
   streaming all changes
   1027 files to transfer, 96.3 KB of data
   transferred 96.3 KB in * seconds (*/sec) (glob)
   searching for changes
   no changes found
+#endif
+#if stream-bundle2
+  $ hg clone --stream -U http://localhost:$HGPORT clone1
+  streaming all changes
+  1027 files to transfer, 96.3 KB of data
+  transferred 96.3 KB in * seconds (* */sec) (glob)
+#endif
 
 --uncompressed is an alias to --stream
 
+#if stream-legacy
   $ hg clone --uncompressed -U http://localhost:$HGPORT clone1-uncompressed
   streaming all changes
   1027 files to transfer, 96.3 KB of data
   transferred 96.3 KB in * seconds (*/sec) (glob)
   searching for changes
   no changes found
+#endif
+#if stream-bundle2
+  $ hg clone --uncompressed -U http://localhost:$HGPORT clone1-uncompressed
+  streaming all changes
+  1027 files to transfer, 96.3 KB of data
+  transferred 96.3 KB in * seconds (* */sec) (glob)
+#endif
 
 Clone with background file closing enabled
 
+#if stream-legacy
   $ hg --debug --config worker.backgroundclose=true --config worker.backgroundcloseminfilecount=1 clone --stream -U http://localhost:$HGPORT clone-background | grep -v adding
   using http://localhost:$HGPORT/
   sending capabilities command
@@ -57,6 +83,28 @@
   bundle2-input-part: total payload size 24
   bundle2-input-bundle: 1 parts total
   checking for updated bookmarks
+#endif
+#if stream-bundle2
+  $ hg --debug --config worker.backgroundclose=true --config worker.backgroundcloseminfilecount=1 clone --stream -U http://localhost:$HGPORT clone-background | grep -v adding
+  using http://localhost:$HGPORT/
+  sending capabilities command
+  query 1; heads
+  sending batch command
+  streaming all changes
+  sending getbundle command
+  bundle2-input-bundle: with-transaction
+  bundle2-input-part: "stream" (params: 4 mandatory) supported
+  applying stream bundle
+  1027 files to transfer, 96.3 KB of data
+  starting 4 threads for background file closing
+  transferred 96.3 KB in * seconds (* */sec) (glob)
+  bundle2-input-part: total payload size 110887
+  bundle2-input-part: "listkeys" (params: 1 mandatory) supported
+  bundle2-input-part: "phase-heads" supported
+  bundle2-input-part: total payload size 24
+  bundle2-input-bundle: 2 parts total
+  checking for updated bookmarks
+#endif
 
 Cannot stream clone when there are secret changesets
 
@@ -79,12 +127,20 @@
   $ cat hg.pid > $DAEMON_PIDS
   $ cd ..
 
+#if stream-legacy
   $ hg clone --stream -U http://localhost:$HGPORT secret-allowed
   streaming all changes
   1027 files to transfer, 96.3 KB of data
   transferred 96.3 KB in * seconds (*/sec) (glob)
   searching for changes
   no changes found
+#endif
+#if stream-bundle2
+  $ hg clone --stream -U http://localhost:$HGPORT secret-allowed
+  streaming all changes
+  1027 files to transfer, 96.3 KB of data
+  transferred 96.3 KB in * seconds (* */sec) (glob)
+#endif
 
   $ killdaemons.py
 
@@ -186,6 +242,7 @@
 
 clone it
 
+#if stream-legacy
   $ hg clone --stream http://localhost:$HGPORT with-bookmarks
   streaming all changes
   1027 files to transfer, 96.3 KB of data
@@ -194,5 +251,14 @@
   no changes found
   updating to branch default
   1025 files updated, 0 files merged, 0 files removed, 0 files unresolved
+#endif
+#if stream-bundle2
+  $ hg clone --stream http://localhost:$HGPORT with-bookmarks
+  streaming all changes
+  1027 files to transfer, 96.3 KB of data
+  transferred 96.3 KB in * seconds (* */sec) (glob)
+  updating to branch default
+  1025 files updated, 0 files merged, 0 files removed, 0 files unresolved
+#endif
   $ hg -R with-bookmarks bookmarks
      some-bookmark             1:c17445101a72