narrow: move the code to generate a widening bundle2 to core
authorPulkit Goyal <pulkit@yandex-team.ru>
Fri, 05 Oct 2018 20:24:07 +0300
changeset 40072 1ea80ac13f19
parent 40071 e8132a8897da
child 40073 e92454e69dc3
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
hgext/narrow/narrowbundle2.py
hgext/narrow/narrowwirepeer.py
mercurial/bundle2.py
--- a/hgext/narrow/narrowbundle2.py	Tue Oct 02 17:09:56 2018 +0300
+++ b/hgext/narrow/narrowbundle2.py	Fri Oct 05 20:24:07 2018 +0300
@@ -50,40 +50,6 @@
     caps[NARROWCAP] = ['v0']
     return caps
 
-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 = bundle2.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([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
-
 # Serve a changegroup for a client with a narrow clone.
 def getbundlechangegrouppart_narrow(bundler, repo, source,
                                     bundlecaps=None, b2caps=None, heads=None,
--- a/hgext/narrow/narrowwirepeer.py	Tue Oct 02 17:09:56 2018 +0300
+++ b/hgext/narrow/narrowwirepeer.py	Fri Oct 05 20:24:07 2018 +0300
@@ -21,8 +21,6 @@
     wireprotov1server,
 )
 
-from . import narrowbundle2
-
 def uisetup():
     extensions.wrapfunction(wireprotov1server, '_capabilities', addnarrowcap)
     wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden
@@ -95,7 +93,7 @@
                                     exclude=oldexcludes)
         diffmatch = matchmod.differencematcher(newmatch, oldmatch)
 
-        bundler = narrowbundle2.widen_bundle(repo, diffmatch, common, known,
+        bundler = bundle2.widen_bundle(repo, diffmatch, common, known,
                                              cgversion, ellipses)
     except error.Abort as exc:
         bundler = bundle2.bundle20(repo.ui)
--- 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