diff mercurial/bundle2.py @ 40073:1ea80ac13f19

narrow: move the code to generate a widening bundle2 to core This is a part of moving more narrow related bits to core. Differential Revision: https://phab.mercurial-scm.org/D4888
author Pulkit Goyal <pulkit@yandex-team.ru>
date Fri, 05 Oct 2018 20:24:07 +0300
parents d89d5bc06eaa
children 58ebf5083843
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue Oct 02 17:09:56 2018 +0300
+++ b/mercurial/bundle2.py	Fri Oct 05 20:24:07 2018 +0300
@@ -2266,3 +2266,37 @@
     repo.ui.debug('applying stream bundle\n')
     streamclone.applybundlev2(repo, part, filecount, bytecount,
                               requirements)
+
+def widen_bundle(repo, diffmatcher, common, known, cgversion, ellipses):
+    """generates bundle2 for widening a narrow clone
+
+    repo is the localrepository instance
+    diffmatcher is a differencemacther of '(newincludes, newexcludes) -
+    (oldincludes, oldexcludes)'
+    common is set of common heads between server and client
+    known is a set of revs known on the client side (used in ellipses)
+    cgversion is the changegroup version to send
+    ellipses is boolean value telling whether to send ellipses data or not
+
+    returns bundle2 of the data required for extending
+    """
+    bundler = bundle20(repo.ui)
+    commonnodes = set()
+    cl = repo.changelog
+    for r in repo.revs("::%ln", common):
+        commonnodes.add(cl.node(r))
+    if commonnodes:
+        # XXX: we should only send the filelogs (and treemanifest). user
+        # already has the changelog and manifest
+        packer = changegroup.getbundler(cgversion, repo,
+                                        filematcher=diffmatcher,
+                                        fullnodes=commonnodes)
+        cgdata = packer.generate(set([nodemod.nullid]), list(commonnodes),
+                                 False, 'narrow_widen', changelog=False)
+
+        part = bundler.newpart('changegroup', data=cgdata)
+        part.addparam('version', cgversion)
+        if 'treemanifest' in repo.requirements:
+            part.addparam('treemanifest', '1')
+
+    return bundler