diff mercurial/exchange.py @ 37169:6f467adf9f05

bundle: add the possibility to bundle a stream v2 part Differential Revision: https://phab.mercurial-scm.org/D1954
author Boris Feld <boris.feld@octobus.net>
date Wed, 31 Jan 2018 11:09:20 +0100
parents 6c7a6b04b274
children a2b350d9f6ae
line wrap: on
line diff
--- a/mercurial/exchange.py	Wed Jan 31 10:55:15 2018 +0100
+++ b/mercurial/exchange.py	Wed Jan 31 11:09:20 2018 +0100
@@ -241,14 +241,6 @@
     else:
         raise error.Abort(_('%s: unknown bundle version %s') % (fname, version))
 
-def _formatrequirementsspec(requirements):
-    return urlreq.quote(','.join(sorted(requirements)))
-
-def _formatrequirementsparams(requirements):
-    requirements = _formatrequirementsspec(requirements)
-    params = "%s%s" % (urlreq.quote("requirements="), requirements)
-    return params
-
 def getbundlespec(ui, fh):
     """Infer the bundlespec from a bundle file handle.
 
@@ -297,7 +289,8 @@
         return '%s-%s' % (comp, version)
     elif isinstance(b, streamclone.streamcloneapplier):
         requirements = streamclone.readbundle1header(fh)[2]
-        return 'none-packed1;%s' % _formatrequirementsparams(requirements)
+        formatted = bundle2._formatrequirementsparams(requirements)
+        return 'none-packed1;%s' % formatted
     else:
         raise error.Abort(_('unknown bundle type: %s') % b)
 
@@ -1825,29 +1818,8 @@
     return info, bundler.getchunks()
 
 @getbundle2partsgenerator('stream2')
-def _getbundlestream2(bundler, repo, source, bundlecaps=None,
-                      b2caps=None, heads=None, common=None, **kwargs):
-    if not kwargs.get('stream', False):
-        return
-
-    if not streamclone.allowservergeneration(repo):
-        raise error.Abort(_('stream data requested but server does not allow '
-                            'this feature'),
-                          hint=_('well-behaved clients should not be '
-                                 'requesting stream data from servers not '
-                                 'advertising it; the client may be buggy'))
-
-    # Stream clones don't compress well. And compression undermines a
-    # goal of stream clones, which is to be fast. Communicate the desire
-    # to avoid compression to consumers of the bundle.
-    bundler.prefercompressed = False
-
-    filecount, bytecount, it = streamclone.generatev2(repo)
-    requirements = _formatrequirementsspec(repo.requirements)
-    part = bundler.newpart('stream2', data=it)
-    part.addparam('bytecount', '%d' % bytecount, mandatory=True)
-    part.addparam('filecount', '%d' % filecount, mandatory=True)
-    part.addparam('requirements', requirements, mandatory=True)
+def _getbundlestream2(bundler, repo, *args, **kwargs):
+    return bundle2.addpartbundlestream2(bundler, repo, **kwargs)
 
 @getbundle2partsgenerator('changegroup')
 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,