bundle2: add a 'stream' part handler for stream cloning
authorBoris Feld <boris.feld@octobus.net>
Wed, 17 Jan 2018 16:35:22 +0100
changeset 35758 b996ddf5963d
parent 35757 bbf7abd09ff0
child 35759 c24dad55ac19
bundle2: add a 'stream' part handler for stream cloning The part contains the necessary arguments and payload to handle a stream bundle v2. It will be put to use in later changesets.
mercurial/bundle2.py
--- a/mercurial/bundle2.py	Thu Jan 18 00:45:27 2018 +0100
+++ b/mercurial/bundle2.py	Wed Jan 17 16:35:22 2018 +0100
@@ -164,6 +164,7 @@
     phases,
     pushkey,
     pycompat,
+    streamclone,
     tags,
     url,
     util,
@@ -2114,3 +2115,30 @@
             key = "USERVAR_" + key
             hookargs[key] = value
         op.addhookargs(hookargs)
+
+@parthandler('stream', ('requirements', 'filecount', 'bytecount', 'version'))
+def handlestreambundle(op, part):
+
+    version = part.params['version']
+    if version != 'v2':
+        raise error.Abort(_('unknown stream bundle version %s') % version)
+    requirements = part.params['requirements'].split()
+    filecount = int(part.params['filecount'])
+    bytecount = int(part.params['bytecount'])
+
+    repo = op.repo
+    if len(repo):
+        msg = _('cannot apply stream clone to non empty repository')
+        raise error.Abort(msg)
+
+    repo.ui.debug('applying stream bundle\n')
+    streamclone.applybundlev2(repo, part, filecount, bytecount,
+                              requirements)
+
+    # new requirements = old non-format requirements +
+    #                    new format-related remote requirements
+    # requirements from the streamed-in repository
+    repo.requirements = set(requirements) | (
+            repo.requirements - repo.supportedformats)
+    repo._applyopenerreqs()
+    repo._writerequirements()