diff hgext/narrow/narrowmerge.py @ 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 53fe5a1a92bd
children 8f37b5fc5abf
line wrap: on
line diff
--- 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