D2495: narrow: drop safehasattr() checks for always-present repo.narrowmatch

2018-03-01 Thread martinvonz (Martin von Zweigbergk)
martinvonz added inline comments.

INLINE COMMENTS

> yuja wrote in narrowmerge.py:71
> s/not// ?

Yep, it definitely looks like it should be. Fixed in "committed"

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2495

To: martinvonz, durin42, #hg-reviewers, indygreg
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2495: narrow: drop safehasattr() checks for always-present repo.narrowmatch

2018-03-01 Thread yuja (Yuya Nishihara)
yuja added inline comments.

INLINE COMMENTS

> narrowmerge.py:71
> +narrowmatch = repo.narrowmatch()
> +if not narrowmatch.always():
>  return u1, u2

s/not// ?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2495

To: martinvonz, durin42, #hg-reviewers, indygreg
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2495: narrow: drop safehasattr() checks for always-present repo.narrowmatch

2018-02-28 Thread martinvonz (Martin von Zweigbergk)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGa9d88301d495: narrow: drop safehasattr() checks for 
always-present repo.narrowmatch (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2495?vs=6195&id=6227

REVISION DETAIL
  https://phab.mercurial-scm.org/D2495

AFFECTED 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

CHANGE DETAILS

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 ''
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/narrowmerge.py b/hgext/narrow/narrowmerge.py
--- a/hgext/narrow/narrowmerge.py
+++ b/hgext/narrow/narrowmerge.py
@@ -13,21 +13,20 @@
 error,
 extensions,
 merge,
-util,
 )
 
 def setup():
 def _manifestmerge(orig, repo, wctx, p2, pa, branchmerge, *args, **kwargs):
 """Filter updates to only lay out files that match the narrow spec."""
 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/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 _checkcopi

D2495: narrow: drop safehasattr() checks for always-present repo.narrowmatch

2018-02-28 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I've added checks for repo.narrowmatch().always() in order to restore
  some of the fast paths for non-narrow repos.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2495

AFFECTED 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

CHANGE DETAILS

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 ''
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/narrowmerge.py b/hgext/narrow/narrowmerge.py
--- a/hgext/narrow/narrowmerge.py
+++ b/hgext/narrow/narrowmerge.py
@@ -13,21 +13,20 @@
 error,
 extensions,
 merge,
-util,
 )
 
 def setup():
 def _manifestmerge(orig, repo, wctx, p2, pa, branchmerge, *args, **kwargs):
 """Filter updates to only lay out files that match the narrow spec."""
 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/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, srcct