diff mercurial/wireproto.py @ 21069:0a9cae236738

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.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 15 Apr 2014 15:20:33 -0400
parents 4d9d490d7bbe
children 0879352d67d8
line wrap: on
line diff
--- 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')