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) 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