bundle2: allow bundle2 for pulling over the wire
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 15 Apr 2014 15:20:33 -0400
changeset 21069 0a9cae236738
parent 21068 c15b66a6bbb4
child 21070 408877d491fb
bundle2: allow bundle2 for pulling over the wire This changeset makes `wireprotocol` peers advertise bundle2 capability and comply with bundle2 `getbundle` requests. Note that advertising bundle2 could make a client try to use it for push. Such pushes would fail. However, I do not expect any human being to have enabled bundle2 on their server yet.
mercurial/wireproto.py
tests/test-bundle2.t
--- a/mercurial/wireproto.py	Tue Apr 15 11:27:55 2014 -0400
+++ b/mercurial/wireproto.py	Tue Apr 15 15:20:33 2014 -0400
@@ -8,7 +8,7 @@
 import urllib, tempfile, os, sys
 from i18n import _
 from node import bin, hex
-import changegroup as changegroupmod
+import changegroup as changegroupmod, bundle2
 import peer, error, encoding, util, store, exchange
 
 
@@ -335,7 +335,10 @@
         if bundlecaps is not None:
             opts['bundlecaps'] = ','.join(bundlecaps)
         f = self._callcompressable("getbundle", **opts)
-        return changegroupmod.unbundle10(f, 'UN')
+        if bundlecaps is not None and 'HG20' in bundlecaps:
+            return bundle2.unbundle20(self.ui, f)
+        else:
+            return changegroupmod.unbundle10(f, 'UN')
 
     def unbundle(self, cg, heads, source):
         '''Send cg (a readable file-like object representing the
@@ -565,6 +568,8 @@
         # otherwise, add 'streamreqs' detailing our local revlog format
         else:
             caps.append('streamreqs=%s' % ','.join(requiredformats))
+    if repo.ui.configbool('server', 'bundle2', False):
+        caps.append('bundle2')
     caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority))
     caps.append('httpheader=1024')
     return caps
@@ -602,7 +607,7 @@
             opts[k] = decodelist(v)
         elif k == 'bundlecaps':
             opts[k] = set(v.split(','))
-    cg = changegroupmod.getbundle(repo, 'serve', **opts)
+    cg = exchange.getbundle(repo, 'serve', **opts)
     return streamres(proto.groupchunks(cg))
 
 @wireprotocommand('heads')
--- a/tests/test-bundle2.t	Tue Apr 15 11:27:55 2014 -0400
+++ b/tests/test-bundle2.t	Tue Apr 15 15:20:33 2014 -0400
@@ -156,6 +156,8 @@
   > bundle2=$TESTTMP/bundle2.py
   > [server]
   > bundle2=True
+  > [ui]
+  > ssh=python "$TESTDIR/dummyssh"
   > EOF
 
 The extension requires a repo (currently unused)
@@ -682,3 +684,31 @@
   adding manifests
   adding file changes
   added 1 changesets with 0 changes to 0 files (-1 heads)
+
+pull over ssh
+
+  $ hg -R other pull ssh://user@dummy/main -r 02de42196ebe --traceback
+  pulling from ssh://user@dummy/main
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  (run 'hg heads' to see heads, 'hg merge' to merge)
+
+pull over http
+
+  $ hg -R main serve -p $HGPORT -d --pid-file=main.pid -E main-error.log
+  $ cat main.pid >> $DAEMON_PIDS
+
+  $ hg -R other pull http://localhost:$HGPORT/ -r 42ccdea3bb16
+  pulling from http://localhost:$HGPORT/
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  (run 'hg heads .' to see heads, 'hg merge' to merge)
+  $ cat main-error.log
+
+