pulkit created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This patch introduces a wireprotocol command narrow_widen() which will be used
  to widen a narrow copy using `hg tracked` command provided by narrow 
extension.
  
  The wireprotocol command takes the old and new includes and excludes, common
  heads, changegroup version and generates a changegroup of the required data 
and
  send it. The clients receives the changegroup and applies that.
  
  I am not sure whether we need changegroup version as an argument to the 
command
  as I *think* narrow needs changegroup3.
  
  This is my first working attempt on having a wireprotocol command, I have 
mostly
  copied code from existing commands. I need to specify the arguments instead of
  just specifying "*". I think one more argument which will be required is
  ellipses which will tell whether the widening request is ellipses based or 
not.
  This will help in ellipses enabled server to serve request to non-ellipses 
based
  clients.
  
  The tests shows that we don't exchange phase data now while widening which is
  nice.
  
  I think porting this command to ellipses cases will still require exchanging
  bundle2 or we need to refactor how KILLS are send. Any suggestion on that will
  be greatly loved.
  
  This is an RFC because it's working but I don't have strong understanding of
  some parts how they work like having a cgunpacker both on server and client
  sides.
  
  All the tests passes except pyflakes because we are not using the value of ret
  after applying changegorup in narrowcommands.py

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4813

AFFECTED FILES
  hgext/narrow/narrowcommands.py
  hgext/narrow/narrowwirepeer.py
  tests/test-narrow-widen-no-ellipsis.t

CHANGE DETAILS

diff --git a/tests/test-narrow-widen-no-ellipsis.t 
b/tests/test-narrow-widen-no-ellipsis.t
--- a/tests/test-narrow-widen-no-ellipsis.t
+++ b/tests/test-narrow-widen-no-ellipsis.t
@@ -104,23 +104,13 @@
   sending batch command
   searching for changes
   all local heads known remotely
-  no changes found
-  sending getbundle command
-  bundle2-input-bundle: with-transaction
-  bundle2-input-part: "changegroup" (params: * mandatory) supported (glob)
+  sending narrow_widen command
   adding changesets
   adding manifests
   adding widest/ revisions (tree !)
   adding file changes
-  adding widest/f revisions (tree !)
+  adding widest/f revisions
   added 0 changesets with 1 changes to 1 files
-  bundle2-input-part: total payload size * (glob)
-  bundle2-input-part: "listkeys" (params: 1 mandatory) supported
-  bundle2-input-part: "phase-heads" supported
-  bundle2-input-part: total payload size 24
-  bundle2-input-bundle: 2 parts total
-  checking for updated bookmarks
-  3 local changesets published
    widest/f: add from widened narrow clone -> g
   getting widest/f
   $ hg tracked
@@ -143,6 +133,7 @@
   adding file changes
   added 5 changesets with 4 changes to 2 files
   new changesets *:* (glob)
+  3 local changesets published
   (run 'hg update' to get a working copy)
   $ hg update -r 'desc("add wider")'
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -179,12 +170,10 @@
   $ hg tracked --addinclude wider
   comparing with ssh://user@dummy/master
   searching for changes
-  no changes found
   adding changesets
   adding manifests
   adding file changes
   added 0 changesets with 1 changes to 1 files
-  5 local changesets published
   $ hg tracked
   I path:inside
   I path:wider
@@ -284,12 +273,10 @@
   $ hg tracked --addinclude d1
   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 1 files
-  11 local changesets published
   $ hg tracked
   I path:d0
   I path:d1
@@ -376,12 +363,10 @@
   $ hg --config hooks.pretxnchangegroup.bad=false tracked --addinclude d1
   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 1 files
-  11 local changesets published
   $ hg log -T "{if(ellipsis, '...')}{rev}: {desc}\n"
   11: local
   10: add d10/f
diff --git a/hgext/narrow/narrowwirepeer.py b/hgext/narrow/narrowwirepeer.py
--- a/hgext/narrow/narrowwirepeer.py
+++ b/hgext/narrow/narrowwirepeer.py
@@ -8,14 +8,23 @@
 from __future__ import absolute_import
 
 from mercurial import (
+    changegroup,
     extensions,
     hg,
+    match as matchmod,
+    narrowspec,
+    util,
     wireprotoserver,
+    wireprototypes,
+    wireprotov1peer,
     wireprotov1server,
 )
 
+from . import narrowbundle2
+
 def uisetup():
     extensions.wrapfunction(wireprotov1server, '_capabilities', addnarrowcap)
+    wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden
 
 def addnarrowcap(orig, repo, proto):
     """add the narrow capability to the server"""
@@ -37,3 +46,43 @@
             return orig(cmd, *args, **kwargs)
         extensions.wrapfunction(peer, '_calltwowaystream', wrapped)
     hg.wirepeersetupfuncs.append(wirereposetup)
+
+@wireprotov1server.wireprotocommand('narrow_widen', '*', permission='pull')
+def narrow_widen(repo, proto, args):
+    """wireprotocol command to send data when a narrow clone is widen. We will
+    be sending a changegroup here.
+
+    The current set of arguments which are required:
+    oldincludes: the old includes of the narrow copy
+    oldexcludes: the old excludes of the narrow copy
+    newincludes: the new includes of the narrow copy
+    newexcludes: the new excludes of the narrow copy
+    common: set of nodes which are common between the server and client
+    cgversion(maybe): the changegroup version to produce
+    """
+
+    oldincludes = wireprototypes.decodelist(args.get('oldincludes'))
+    newincludes = wireprototypes.decodelist(args.get('newincludes'))
+    oldexcludes = wireprototypes.decodelist(args.get('oldexcludes'))
+    newexcludes = wireprototypes.decodelist(args.get('newexcludes'))
+    common = wireprototypes.decodelist(args.get('common'))
+    cgversion = args.get('cgversion')
+    newmatch = narrowspec.match(repo.root, include=newincludes,
+                                exclude=newexcludes)
+    oldmatch = narrowspec.match(repo.root, include=oldincludes,
+                                exclude=oldexcludes)
+    diffmatch = matchmod.differencematcher(newmatch, oldmatch)
+
+    # get changegroup data
+    cg = narrowbundle2.widen_changegroup(repo, diffmatch, common, cgversion)
+    cg = changegroup.cg3unpacker(util.chunkbuffer(cg), None)
+    gen = iter(lambda: cg.read(32768), '')
+    return wireprototypes.streamres(gen=gen)
+
+def peernarrowwiden(remote, **kwargs):
+    for ch in ('oldincludes', 'newincludes', 'oldexcludes', 'newexcludes',
+               'common'):
+        kwargs[ch] = wireprototypes.encodelist(kwargs[ch])
+
+    f = remote._callcompressable('narrow_widen', **kwargs)
+    return changegroup.cg3unpacker(f, None)
diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py
+++ b/hgext/narrow/narrowcommands.py
@@ -289,8 +289,19 @@
             with ds.parentchange():
                 ds.setparents(p1, p2)
         else:
-            with wrappedextraprepare:
-                exchange.pull(repo, remote, heads=common)
+            common = commoninc[0]
+            with repo.transaction('widening') as tr,\
+                 remote.commandexecutor() as e:
+                cg = e.callcommand('narrow_widen', {
+                    'oldincludes': oldincludes,
+                    'oldexcludes': oldexcludes,
+                    'newincludes': newincludes,
+                    'newexcludes': newexcludes,
+                    'cgversion': '03',
+                    'common': common,
+                }).result()
+
+                ret = cg.apply(repo, tr, 'narrow_widen', remote.url())
 
         repo.setnewnarrowpats()
         actions = {k: [] for k in 'a am f g cd dc r dm dg m e k p pr'.split()}



To: pulkit, durin42, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to