diff --git a/hgext/narrow/__init__.py b/hgext/narrow/__init__.py --- a/hgext/narrow/__init__.py +++ b/hgext/narrow/__init__.py @@ -84,8 +84,7 @@ # be None from core. If another extension passes a matcher (unlikely), # we'll have to fail until matchers can be composed more easily. assert matcher is None - matcher = getattr(repo, 'narrowmatch', lambda: None)() - orig(self, repo, matcher) + orig(self, repo, repo.narrowmatch()) def extsetup(ui): extensions.wrapfunction(verifymod.verifier, '__init__', _verifierinit) diff --git a/hgext/narrow/narrowchangegroup.py b/hgext/narrow/narrowchangegroup.py --- a/hgext/narrow/narrowchangegroup.py +++ b/hgext/narrow/narrowchangegroup.py @@ -23,12 +23,12 @@ def setup(): def _cgmatcher(cgpacker): - localmatcher = getattr(cgpacker._repo, 'narrowmatch', lambda: None)() + localmatcher = cgpacker._repo.narrowmatch() remotematcher = getattr(cgpacker, '_narrow_matcher', lambda: None)() - if localmatcher and remotematcher: + if remotematcher: return matchmod.intersectmatchers(localmatcher, remotematcher) else: - return localmatcher or remotematcher + return localmatcher def prune(orig, self, revlog, missing, commonrevs): if isinstance(revlog, manifest.manifestrevlog): diff --git a/hgext/narrow/narrowcopies.py b/hgext/narrow/narrowcopies.py --- a/hgext/narrow/narrowcopies.py +++ b/hgext/narrow/narrowcopies.py @@ -11,23 +11,22 @@ from mercurial import ( copies, extensions, - util, ) def setup(repo): def _computeforwardmissing(orig, a, b, match=None): missing = orig(a, b, match) - if util.safehasattr(repo, 'narrowmatch'): - narrowmatch = repo.narrowmatch() - missing = [f for f in missing if narrowmatch(f)] + narrowmatch = repo.narrowmatch() + if narrowmatch.always(): + return missing + missing = [f for f in missing if narrowmatch(f)] return missing def _checkcopies(orig, srcctx, dstctx, f, base, tca, remotebase, limit, data): - if util.safehasattr(repo, 'narrowmatch'): - narrowmatch = repo.narrowmatch() - if not narrowmatch(f): - return + narrowmatch = repo.narrowmatch() + if not narrowmatch(f): + return orig(srcctx, dstctx, f, base, tca, remotebase, limit, data) extensions.wrapfunction(copies, '_computeforwardmissing', diff --git a/hgext/narrow/narrowmerge.py b/hgext/narrow/narrowmerge.py --- a/hgext/narrow/narrowmerge.py +++ b/hgext/narrow/narrowmerge.py @@ -13,7 +13,6 @@ error, extensions, merge, - util, ) def setup(): @@ -22,12 +21,12 @@ actions, diverge, renamedelete = orig( repo, wctx, p2, pa, branchmerge, *args, **kwargs) - if not util.safehasattr(repo, 'narrowmatch'): + narrowmatch = repo.narrowmatch() + if narrowmatch.always(): return actions, diverge, renamedelete nooptypes = set(['k']) # TODO: handle with nonconflicttypes nonconflicttypes = set('a am c cm f g r e'.split()) - narrowmatch = repo.narrowmatch() # We mutate the items in the dict during iteration, so iterate # over a copy. for f, action in list(actions.items()): @@ -51,8 +50,8 @@ extensions.wrapfunction(merge, 'manifestmerge', _manifestmerge) def _checkcollision(orig, repo, wmf, actions): - if util.safehasattr(repo, 'narrowmatch'): - narrowmatch = repo.narrowmatch() + narrowmatch = repo.narrowmatch() + if not narrowmatch.always(): wmf = wmf.matches(narrowmatch) if actions: narrowactions = {} @@ -68,10 +67,10 @@ def _computenonoverlap(orig, repo, *args, **kwargs): u1, u2 = orig(repo, *args, **kwargs) - if not util.safehasattr(repo, 'narrowmatch'): + narrowmatch = repo.narrowmatch() + if not narrowmatch.always(): return u1, u2 - narrowmatch = repo.narrowmatch() u1 = [f for f in u1 if narrowmatch(f)] u2 = [f for f in u2 if narrowmatch(f)] return u1, u2 diff --git a/hgext/narrow/narrowpatch.py b/hgext/narrow/narrowpatch.py --- a/hgext/narrow/narrowpatch.py +++ b/hgext/narrow/narrowpatch.py @@ -10,14 +10,13 @@ from mercurial import ( extensions, patch, - util, ) def setup(repo): def _filepairs(orig, *args): """Only includes files within the narrow spec in the diff.""" - if util.safehasattr(repo, 'narrowmatch'): - narrowmatch = repo.narrowmatch() + narrowmatch = repo.narrowmatch() + if not narrowmatch.always(): for x in orig(*args): f1, f2, copyop = x if ((not f1 or narrowmatch(f1)) and @@ -29,8 +28,8 @@ def trydiff(orig, repo, revs, ctx1, ctx2, modified, added, removed, copy, getfilectx, *args, **kwargs): - if util.safehasattr(repo, 'narrowmatch'): - narrowmatch = repo.narrowmatch() + narrowmatch = repo.narrowmatch() + if not narrowmatch.always(): modified = [f for f in modified if narrowmatch(f)] added = [f for f in added if narrowmatch(f)] removed = [f for f in removed if narrowmatch(f)] diff --git a/hgext/narrow/narrowtemplates.py b/hgext/narrow/narrowtemplates.py --- a/hgext/narrow/narrowtemplates.py +++ b/hgext/narrow/narrowtemplates.py @@ -10,7 +10,6 @@ from mercurial import ( registrar, revlog, - util, ) keywords = {} @@ -33,8 +32,8 @@ def outsidenarrow(repo, ctx, templ, **args): """String. 'outsidenarrow' if the change affects no tracked files, else ''.""" - if util.safehasattr(repo, 'narrowmatch'): - m = repo.narrowmatch() + m = repo.narrowmatch() + if not m.always(): if not any(m(f) for f in ctx.files()): return 'outsidenarrow' return ''