# HG changeset patch # User Martin von Zweigbergk # Date 2018-09-28 19:29:21 # Node ID 4fd0fac4892213a5f3a6a460366e026a42e66cff # Parent a4d62ff9a86d2239a1f6c0e4493243f37460cbce localrepo: allow narrowmatch() to accept matcher to intersect with It's pretty common that we need to intersect a matcher we already have (usually from the user) with the narrow matcher. Let's make repo.narrowmatch() take an optional matcher to intersect with. Differential Revision: https://phab.mercurial-scm.org/D4896 diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -1271,8 +1271,7 @@ def getbundler(version, repo, bundlecaps # Requested files could include files not in the local store. So # filter those out. - filematcher = matchmod.intersectmatchers(repo.narrowmatch(), - filematcher) + filematcher = repo.narrowmatch(filematcher) fn = _packermap[version][0] return fn(repo, filematcher, bundlecaps, ellipses=ellipses, diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -44,7 +44,6 @@ from . import ( help, hg, logcmdutil, - match as matchmod, merge as mergemod, narrowspec, obsolete, @@ -1970,7 +1969,7 @@ def diff(ui, repo, *pats, **opts): diffopts = patch.diffallopts(ui, opts) m = scmutil.match(ctx2, pats, opts) - m = matchmod.intersectmatchers(m, repo.narrowmatch()) + m = repo.narrowmatch(m) ui.pager('diff') logcmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, listsubrepos=opts.get('subrepos'), diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1200,8 +1200,14 @@ class localrepository(object): include, exclude = self.narrowpats return narrowspec.match(self.root, include=include, exclude=exclude) - # TODO(martinvonz): make this property-like instead? - def narrowmatch(self): + def narrowmatch(self, match=None): + """matcher corresponding the the repo's narrowspec + + If `match` is given, then that will be intersected with the narrow + matcher. + """ + if match: + return matchmod.intersectmatchers(match, self._narrowmatch) return self._narrowmatch def setnarrowpats(self, newincludes, newexcludes):