narrow: add server logic to send cg while widening without ellipsis
authorPulkit Goyal <pulkit@yandex-team.ru>
Sun, 26 Aug 2018 20:20:34 +0300
changeset 39356 c8e4eae84808
parent 39355 bca0546a44bf
child 39357 2b8adb7ca39a
narrow: add server logic to send cg while widening without ellipsis Before this patch, if you try to widen a narrow clone without ellipsis enabled, it will be broken and the exchange.pull() done by tracked command to widen the clone will be no-op because no custom logic exists for this and server sees that we have all csets and it says `no changes found`. The widening with ellipsis send KILL for existing changegroups and send new changegroups because of the change in ellipsis hash, but we can prevent that in non-ellipsis cases. This patch adds server side logic to send the changegroups for the changesets which are on the client again with filelogs and manifests for the new includes. This is a very starting implementation and we send changegroups and manifests too while we can prevent them. Following things can definitely be improved in the logic this patch adds: 1) Send just the filelogs and treemanifests 2) Send the filelogs only for the additions in the include I tried 1) here but the code is coupled tightly and the way I was able to do that was hacking into the changegroup generation code in a very dirty way, like adding conditionals and preventing the yield. This patch also adds a 'widen' kwarg to prevent other commands except widening to go through that codepath. The test changes demonstrate that the new implementation is correct and fixes things. Differential Revision: https://phab.mercurial-scm.org/D4383
hgext/narrow/narrowbundle2.py
hgext/narrow/narrowcommands.py
tests/test-narrow-widen-non-ellipsis.t
--- a/hgext/narrow/narrowbundle2.py	Mon Aug 27 13:30:08 2018 +0300
+++ b/hgext/narrow/narrowbundle2.py	Sun Aug 26 20:20:34 2018 +0300
@@ -50,6 +50,50 @@
     caps[NARROWCAP] = ['v0']
     return caps
 
+def getbundlechangegrouppart_nonellipsis(bundler, repo, source, bundlecaps=None,
+                                         b2caps=None, heads=None, common=None,
+                                         **kwargs):
+    """Handling changegroup changegroup generation on the server when user
+    is widening their narrowspec"""
+
+    cgversions = b2caps.get('changegroup')
+    if cgversions:  # 3.1 and 3.2 ship with an empty value
+        cgversions = [v for v in cgversions
+                      if v in changegroup.supportedoutgoingversions(repo)]
+        if not cgversions:
+            raise ValueError(_('no common changegroup version'))
+        version = max(cgversions)
+    else:
+        raise ValueError(_("server does not advertise changegroup version,"
+                           " can't negotiate support for ellipsis nodes"))
+
+    include = sorted(filter(bool, kwargs.get(r'includepats', [])))
+    exclude = sorted(filter(bool, kwargs.get(r'excludepats', [])))
+    newmatch = narrowspec.match(repo.root, include=include, exclude=exclude)
+    oldinclude = sorted(filter(bool, kwargs.get(r'oldincludepats', [])))
+    oldexclude = sorted(filter(bool, kwargs.get(r'oldexcludepats', [])))
+    common = set(common or [nullid])
+
+    if (oldinclude != include or oldexclude != exclude):
+        common = repo.revs("::%ln", common)
+        commonnodes = set()
+        cl = repo.changelog
+        for c in common:
+            commonnodes.add(cl.node(c))
+        if commonnodes:
+            # XXX: we should only send the filelogs (and treemanifest). user
+            # already has the changelog and manifest
+            packer = changegroup.getbundler(version, repo,
+                                            filematcher=newmatch,
+                                            fullnodes=commonnodes)
+            cgdata = packer.generate(set([nullid]), list(commonnodes), False,
+                    source)
+
+            part = bundler.newpart('changegroup', data=cgdata)
+            part.addparam('version', version)
+            if 'treemanifest' in repo.requirements:
+                part.addparam('treemanifest', '1')
+
 # Serve a changegroup for a client with a narrow clone.
 def getbundlechangegrouppart_narrow(bundler, repo, source,
                                     bundlecaps=None, b2caps=None, heads=None,
@@ -254,6 +298,7 @@
     getbundleargs = wireprototypes.GETBUNDLE_ARGUMENTS
 
     getbundleargs['narrow'] = 'boolean'
+    getbundleargs['widen'] = 'boolean'
     getbundleargs['depth'] = 'plain'
     getbundleargs['oldincludepats'] = 'csv'
     getbundleargs['oldexcludepats'] = 'csv'
@@ -271,6 +316,8 @@
         if (kwargs.get(r'narrow', False) and
             repo.ui.configbool('experimental', 'narrowservebrokenellipses')):
             getbundlechangegrouppart_narrow(*args, **kwargs)
+        elif kwargs.get(r'widen', False) and kwargs.get(r'narrow', False):
+            getbundlechangegrouppart_nonellipsis(*args, **kwargs)
         else:
             origcgfn(*args, **kwargs)
     exchange.getbundle2partsmapping['changegroup'] = wrappedcgfn
--- a/hgext/narrow/narrowcommands.py	Mon Aug 27 13:30:08 2018 +0300
+++ b/hgext/narrow/narrowcommands.py	Sun Aug 26 20:20:34 2018 +0300
@@ -286,6 +286,7 @@
         # The old{in,ex}cludepats have already been set by orig()
         kwargs['includepats'] = newincludes
         kwargs['excludepats'] = newexcludes
+        kwargs['widen'] = True
     wrappedextraprepare = extensions.wrappedfunction(exchange,
         '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
 
--- a/tests/test-narrow-widen-non-ellipsis.t	Mon Aug 27 13:30:08 2018 +0300
+++ b/tests/test-narrow-widen-non-ellipsis.t	Sun Aug 26 20:20:34 2018 +0300
@@ -89,6 +89,10 @@
   comparing with ssh://user@dummy/master
   searching for changes
   no changes found
+  adding changesets
+  adding manifests
+  adding file changes
+  added 0 changesets with 0 changes to 1 files
   3 local changesets published
   $ hg tracked
   I path:inside
@@ -141,6 +145,10 @@
   comparing with ssh://user@dummy/master
   searching for changes
   no changes found
+  adding changesets
+  adding manifests
+  adding file changes
+  added 0 changesets with 4 changes to 2 files
   5 local changesets published
   abort: path ends in directory separator: widest/
   [255]
@@ -247,6 +255,10 @@
   comparing with ssh://user@dummy/upstream
   searching for changes
   no changes found
+  adding changesets
+  adding manifests
+  adding file changes
+  added 0 changesets with 1 changes to 5 files
   11 local changesets published
   abort: path ends in directory separator: d1/
   [255]
@@ -274,9 +286,12 @@
   checking changesets
   checking manifests
   checking directory manifests
+  warning: orphan data file 'meta/d1/00manifest.i'
   crosschecking files in changesets and manifests
   checking files
+  warning: orphan data file 'data/d1/f.i'
   4 files, 11 changesets, 4 total revisions
+  2 warnings encountered!
 
 Widening preserves parent of local commit
 
@@ -340,6 +355,10 @@
   comparing with ssh://user@dummy/upstream
   searching for changes
   no changes found
+  adding changesets
+  adding manifests
+  adding file changes
+  added 0 changesets with 1 changes to 2 files
   11 local changesets published
   abort: path ends in directory separator: d1/
   [255]