changeset 36502:d0d5eef57fb0

narrow: drop safehasattr() checks for always-present repo.narrowmatch I've added checks for repo.narrowmatch().always() in order to restore some of the fast paths for non-narrow repos. Differential Revision: https://phab.mercurial-scm.org/D2495
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 28 Feb 2018 10:38:09 -0800
parents c28b6d609c47
children ab5f18a9dcac
files hgext/narrow/__init__.py hgext/narrow/narrowchangegroup.py hgext/narrow/narrowcopies.py hgext/narrow/narrowmerge.py hgext/narrow/narrowpatch.py hgext/narrow/narrowtemplates.py
diffstat 6 files changed, 23 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/narrow/__init__.py	Wed Feb 28 12:56:01 2018 -0800
+++ b/hgext/narrow/__init__.py	Wed Feb 28 10:38:09 2018 -0800
@@ -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)
--- a/hgext/narrow/narrowchangegroup.py	Wed Feb 28 12:56:01 2018 -0800
+++ b/hgext/narrow/narrowchangegroup.py	Wed Feb 28 10:38:09 2018 -0800
@@ -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):
--- a/hgext/narrow/narrowcopies.py	Wed Feb 28 12:56:01 2018 -0800
+++ b/hgext/narrow/narrowcopies.py	Wed Feb 28 10:38:09 2018 -0800
@@ -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',
--- a/hgext/narrow/narrowmerge.py	Wed Feb 28 12:56:01 2018 -0800
+++ b/hgext/narrow/narrowmerge.py	Wed Feb 28 10:38:09 2018 -0800
@@ -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 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
--- a/hgext/narrow/narrowpatch.py	Wed Feb 28 12:56:01 2018 -0800
+++ b/hgext/narrow/narrowpatch.py	Wed Feb 28 10:38:09 2018 -0800
@@ -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)]
--- a/hgext/narrow/narrowtemplates.py	Wed Feb 28 12:56:01 2018 -0800
+++ b/hgext/narrow/narrowtemplates.py	Wed Feb 28 10:38:09 2018 -0800
@@ -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 ''