D4530: narrow: drop support for remote expansion (BC)

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Sep 11 22:59:32 UTC 2018


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

REVISION SUMMARY
  Previous patches to validate narrow patterns accidentically dropped
  support for the include: syntax that allows patterns to be expanded
  from a remote.
  
  This feature was never implemented in core and is only implemented on
  Google's custom server. Per @martinvonz's review comment in https://phab.mercurial-scm.org/D4522, it
  is OK to drop this feature since it isn't used.
  
  The concept of this feature does seem useful. I anticipate it making
  a comeback some day in some shape or form. But for now, let's jettison
  the dead code.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/narrow/TODO.rst
  hgext/narrow/narrowcommands.py
  hgext/narrow/narrowwirepeer.py
  mercurial/narrowspec.py

CHANGE DETAILS

diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py
--- a/mercurial/narrowspec.py
+++ b/mercurial/narrowspec.py
@@ -146,9 +146,6 @@
     return matchmod.match(root, '', [], include=include or [],
                           exclude=exclude or [])
 
-def needsexpansion(includes):
-    return [i for i in includes if i.startswith('include:')]
-
 def load(repo):
     try:
         spec = repo.svfs.read(FILENAME)
diff --git a/hgext/narrow/narrowwirepeer.py b/hgext/narrow/narrowwirepeer.py
--- a/hgext/narrow/narrowwirepeer.py
+++ b/hgext/narrow/narrowwirepeer.py
@@ -7,41 +7,16 @@
 
 from __future__ import absolute_import
 
-from mercurial.i18n import _
 from mercurial import (
-    error,
     extensions,
     hg,
-    narrowspec,
-    node,
     wireprotov1server,
 )
 
 NARROWCAP = 'exp-narrow-1'
 ELLIPSESCAP = 'exp-ellipses-1'
 
 def uisetup():
-    def peersetup(ui, peer):
-        # We must set up the expansion before reposetup below, since it's used
-        # at clone time before we have a repo.
-        class expandingpeer(peer.__class__):
-            def expandnarrow(self, narrow_include, narrow_exclude, nodes):
-                ui.status(_("expanding narrowspec\n"))
-                if not self.capable('exp-expandnarrow'):
-                    raise error.Abort(
-                        'peer does not support expanding narrowspecs')
-
-                hex_nodes = (node.hex(n) for n in nodes)
-                new_narrowspec = self._call(
-                    'expandnarrow',
-                    includepats=','.join(narrow_include),
-                    excludepats=','.join(narrow_exclude),
-                    nodes=','.join(hex_nodes))
-
-                return narrowspec.parseserverpatterns(new_narrowspec)
-        peer.__class__ = expandingpeer
-    hg.wirepeersetupfuncs.append(peersetup)
-
     extensions.wrapfunction(wireprotov1server, '_capabilities', addnarrowcap)
 
 def addnarrowcap(orig, repo, proto):
diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py
+++ b/hgext/narrow/narrowcommands.py
@@ -62,25 +62,6 @@
 
     extensions.wrapcommand(commands.table, 'archive', archivenarrowcmd)
 
-def expandpull(pullop, includepats, excludepats):
-    if not narrowspec.needsexpansion(includepats):
-        return includepats, excludepats
-
-    heads = pullop.heads or pullop.rheads
-    includepats, excludepats = pullop.remote.expandnarrow(
-        includepats, excludepats, heads)
-    pullop.repo.ui.debug('Expanded narrowspec to inc=%s, exc=%s\n' % (
-        includepats, excludepats))
-
-    includepats = set(includepats)
-    excludepats = set(excludepats)
-
-    # Nefarious remote could supply unsafe patterns. Validate them.
-    narrowspec.validatepatterns(includepats)
-    narrowspec.validatepatterns(excludepats)
-
-    return includepats, excludepats
-
 def clonenarrowcmd(orig, ui, repo, *args, **opts):
     """Wraps clone command, so 'hg clone' first wraps localrepo.clone()."""
     opts = pycompat.byteskwargs(opts)
@@ -116,10 +97,6 @@
             includepats = narrowspec.parsepatterns(opts['include'])
             excludepats = narrowspec.parsepatterns(opts['exclude'])
 
-            # If necessary, ask the server to expand the narrowspec.
-            includepats, excludepats = expandpull(
-                pullop, includepats, excludepats)
-
             if not includepats and excludepats:
                 # If nothing was included, we assume the user meant to include
                 # everything, except what they asked to exclude.
@@ -292,10 +269,6 @@
 def _widen(ui, repo, remote, commoninc, newincludes, newexcludes):
     newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
 
-    # TODO(martinvonz): Get expansion working with widening/narrowing.
-    if narrowspec.needsexpansion(newincludes):
-        raise error.Abort('Expansion not yet supported on pull')
-
     def pullbundle2extraprepare_widen(orig, pullop, kwargs):
         orig(pullop, kwargs)
         # The old{in,ex}cludepats have already been set by orig()
@@ -402,9 +375,6 @@
         opts['addinclude'].extend(includepats)
         opts['addexclude'].extend(excludepats)
 
-    if narrowspec.needsexpansion(opts['addinclude'] + opts['addexclude']):
-        raise error.Abort('Expansion not yet supported on widen/narrow')
-
     addedincludes = narrowspec.parsepatterns(opts['addinclude'])
     removedincludes = narrowspec.parsepatterns(opts['removeinclude'])
     addedexcludes = narrowspec.parsepatterns(opts['addexclude'])
diff --git a/hgext/narrow/TODO.rst b/hgext/narrow/TODO.rst
--- a/hgext/narrow/TODO.rst
+++ b/hgext/narrow/TODO.rst
@@ -28,10 +28,3 @@
 
 narrowrepo.setnarrowpats() or narrowspec.save() need to make sure
 they're holding the wlock.
-
-Implement a simple version of the expandnarrow wireproto command for
-core. Having configurable shorthands for narrowspecs has been useful
-at Google (and sparse has a similar feature from Facebook), so it
-probably makes sense to implement the feature in core. (Google's
-handler is entirely custom to Google, with a custom format related to
-bazel's build language, so it's not in the narrowhg distribution.)



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


More information about the Mercurial-devel mailing list