D6218: narrow: send specs as bundle2 data instead of param (issue5952) (issue6019)

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Fri Apr 19 17:06:39 EDT 2019


pulkit updated this revision to Diff 14870.
pulkit edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6218?vs=14765&id=14870

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

AFFECTED FILES
  hgext/narrow/narrowbundle2.py
  mercurial/exchange.py

CHANGE DETAILS

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -2213,13 +2213,10 @@
 
     if (kwargs.get(r'narrow', False) and kwargs.get(r'narrow_acl', False)
         and (include or exclude)):
-        narrowspecpart = bundler.newpart('narrow:spec')
-        if include:
-            narrowspecpart.addparam(
-                'include', '\n'.join(include), mandatory=True)
-        if exclude:
-            narrowspecpart.addparam(
-                'exclude', '\n'.join(exclude), mandatory=True)
+        # this is mandatory because otherwise ACL clients won't work
+        narrowspecpart = bundler.newpart('Narrowspec')
+        narrowspecpart.data = '%s\0%s' % ('\n'.join(include),
+                                           '\n'.join(exclude))
 
 @getbundle2partsgenerator('bookmarks')
 def _getbundlebookmarkpart(bundler, repo, source, bundlecaps=None,
diff --git a/hgext/narrow/narrowbundle2.py b/hgext/narrow/narrowbundle2.py
--- a/hgext/narrow/narrowbundle2.py
+++ b/hgext/narrow/narrowbundle2.py
@@ -142,6 +142,10 @@
 
 @bundle2.parthandler(_SPECPART, (_SPECPART_INCLUDE, _SPECPART_EXCLUDE))
 def _handlechangespec_2(op, inpart):
+    # XXX: This bundle2 handling is buggy and should be removed after hg5.2 is
+    # released. New servers will send a mandatory bundle2 part named
+    # 'Narrowspec' and will send specs as data instead of params.
+    # Refer to issue5952 and 6019
     includepats = set(inpart.params.get(_SPECPART_INCLUDE, '').splitlines())
     excludepats = set(inpart.params.get(_SPECPART_EXCLUDE, '').splitlines())
     narrowspec.validatepatterns(includepats)
@@ -153,6 +157,22 @@
     op.repo.setnarrowpats(includepats, excludepats)
     narrowspec.copytoworkingcopy(op.repo)
 
+ at bundle2.parthandler('Narrowspec')
+def _handlenarrowspecs(op, inpart):
+    data = inpart.read()
+    if data:
+        inc, exc = data.split('\0')
+        includepats = set(inc.splitlines())
+        excludepats = set(exc.splitlines())
+    narrowspec.validatepatterns(includepats)
+    narrowspec.validatepatterns(excludepats)
+
+    if not repository.NARROW_REQUIREMENT in op.repo.requirements:
+        op.repo.requirements.add(repository.NARROW_REQUIREMENT)
+        op.repo._writerequirements()
+    op.repo.setnarrowpats(includepats, excludepats)
+    narrowspec.copytoworkingcopy(op.repo)
+
 @bundle2.parthandler(_CHANGESPECPART)
 def _handlechangespec(op, inpart):
     repo = op.repo



To: pulkit, durin42, martinvonz, #hg-reviewers
Cc: indygreg, idlsoft, mercurial-devel


More information about the Mercurial-devel mailing list