D4900: narrow: allow repo.narrowmatch(match) to include exact matches from "match"

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Fri Oct 5 22:36:49 UTC 2018


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

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/narrow/narrowdirstate.py
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1200,13 +1200,22 @@
         include, exclude = self.narrowpats
         return narrowspec.match(self.root, include=include, exclude=exclude)
 
-    def narrowmatch(self, match=None):
+    def narrowmatch(self, match=None, includeexact=False):
         """matcher corresponding the the repo's narrowspec
 
         If `match` is given, then that will be intersected with the narrow
         matcher.
+
+        If `includeexact` is True, then any exact matches from `match` will
+        be included even if they're outside the narrowspec.
         """
         if match:
+            if includeexact and not self._narrowmatch.always():
+                # do not exclude explicitly-specified paths so that they can
+                # be warned later on
+                em = matchmod.exact(match._root, match._cwd, match.files())
+                nm = matchmod.unionmatcher([self._narrowmatch, em])
+                return matchmod.intersectmatchers(match, nm)
             return matchmod.intersectmatchers(match, self._narrowmatch)
         return self._narrowmatch
 
diff --git a/hgext/narrow/narrowdirstate.py b/hgext/narrow/narrowdirstate.py
--- a/hgext/narrow/narrowdirstate.py
+++ b/hgext/narrow/narrowdirstate.py
@@ -10,7 +10,6 @@
 from mercurial.i18n import _
 from mercurial import (
     error,
-    match as matchmod,
 )
 
 def wrapdirstate(repo, dirstate):
@@ -30,11 +29,7 @@
         def walk(self, match, subrepos, unknown, ignored, full=True,
                  narrowonly=True):
             if narrowonly:
-                # hack to not exclude explicitly-specified paths so that they
-                # can be warned later on e.g. dirstate.add()
-                em = matchmod.exact(match._root, match._cwd, match.files())
-                nm = matchmod.unionmatcher([repo.narrowmatch(), em])
-                match = matchmod.intersectmatchers(match, nm)
+                match = repo.narrowmatch(match, includeexact=True)
             return super(narrowdirstate, self).walk(match, subrepos, unknown,
                                                     ignored, full)
 



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


More information about the Mercurial-devel mailing list