Patchwork [3,of,4] match: inverse _anypats(), making it _prefix()

login
register
mail settings
Submitter via Mercurial-devel
Date July 10, 2017, 5:27 p.m.
Message ID <b90074c6fa4739ae6b81.1499707663@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/22209/
State Accepted
Headers show

Comments

via Mercurial-devel - July 10, 2017, 5:27 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1499665323 25200
#      Sun Jul 09 22:42:03 2017 -0700
# Node ID b90074c6fa4739ae6b817d853ebcffd931671933
# Parent  25d89317826e99474cde4b97899903191ef1ba27
match: inverse _anypats(), making it _prefix()
Yuya Nishihara - July 11, 2017, 1:20 p.m.
On Mon, 10 Jul 2017 10:27:43 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1499665323 25200
> #      Sun Jul 09 22:42:03 2017 -0700
> # Node ID b90074c6fa4739ae6b817d853ebcffd931671933
> # Parent  25d89317826e99474cde4b97899903191ef1ba27
> match: inverse _anypats(), making it _prefix()

> +def _prefix(kindpats):
> +    '''Whether all the patterns match a prefix (i.e. recursively)'''
>      for kind, pat, source in kindpats:
> -        if kind in ('glob', 're', 'relglob', 'relre', 'set', 'rootfilesin'):
> -            return True
> +        assert kind not in ('listfile', 'listfile0', 'include', 'subinclude')

"subinclude" isn't expanded by normalize().

> +        if kind not in ('path', 'relpath'):
> +            return False
> +    return True

Other than that, this patch looks good to me.
via Mercurial-devel - July 11, 2017, 1:38 p.m.
On Jul 11, 2017 6:21 AM, "Yuya Nishihara" <yuya@tcha.org> wrote:

On Mon, 10 Jul 2017 10:27:43 -0700, Martin von Zweigbergk via
Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1499665323 25200
> #      Sun Jul 09 22:42:03 2017 -0700
> # Node ID b90074c6fa4739ae6b817d853ebcffd931671933
> # Parent  25d89317826e99474cde4b97899903191ef1ba27
> match: inverse _anypats(), making it _prefix()

> +def _prefix(kindpats):
> +    '''Whether all the patterns match a prefix (i.e. recursively)'''
>      for kind, pat, source in kindpats:
> -        if kind in ('glob', 're', 'relglob', 'relre', 'set',
'rootfilesin'):
> -            return True
> +        assert kind not in ('listfile', 'listfile0', 'include',
'subinclude')

"subinclude" isn't expanded by normalize().


Good catch. Feel free to fix in flight. Otherwise I'll resend later today.


> +        if kind not in ('path', 'relpath'):
> +            return False
> +    return True

Other than that, this patch looks good to me.
Yuya Nishihara - July 11, 2017, 2:04 p.m.
On Tue, 11 Jul 2017 06:38:15 -0700, Martin von Zweigbergk wrote:
> On Jul 11, 2017 6:21 AM, "Yuya Nishihara" <yuya@tcha.org> wrote:
> 
> On Mon, 10 Jul 2017 10:27:43 -0700, Martin von Zweigbergk via
> Mercurial-devel wrote:
> > # HG changeset patch
> > # User Martin von Zweigbergk <martinvonz@google.com>
> > # Date 1499665323 25200
> > #      Sun Jul 09 22:42:03 2017 -0700
> > # Node ID b90074c6fa4739ae6b817d853ebcffd931671933
> > # Parent  25d89317826e99474cde4b97899903191ef1ba27
> > match: inverse _anypats(), making it _prefix()
> 
> > +def _prefix(kindpats):
> > +    '''Whether all the patterns match a prefix (i.e. recursively)'''
> >      for kind, pat, source in kindpats:
> > -        if kind in ('glob', 're', 'relglob', 'relre', 'set',
> 'rootfilesin'):
> > -            return True
> > +        assert kind not in ('listfile', 'listfile0', 'include',
> 'subinclude')
> 
> "subinclude" isn't expanded by normalize().
> 
> Good catch. Feel free to fix in flight. Otherwise I'll resend later today.

Can you send new version?

Perhaps it can be fixed by moving 'subinclude' to the "kind not in then False"
list, but I don't want to push a wrong patch with your name.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -373,7 +373,7 @@ 
         super(patternmatcher, self).__init__(root, cwd, badfn)
 
         self._files = _explicitfiles(kindpats)
-        self._anypats = _anypats(kindpats)
+        self._prefix = _prefix(kindpats)
         self._pats, self.matchfn = _buildmatch(ctx, kindpats, '$', listsubrepos,
                                                root)
 
@@ -382,7 +382,7 @@ 
         return set(util.dirs(self._fileset)) | {'.'}
 
     def visitdir(self, dir):
-        if self.prefix() and dir in self._fileset:
+        if self._prefix and dir in self._fileset:
             return 'all'
         return ('.' in self._fileset or
                 dir in self._fileset or
@@ -391,7 +391,7 @@ 
                     for parentdir in util.finddirs(dir)))
 
     def prefix(self):
-        return not self._anypats
+        return self._prefix
 
     def __repr__(self):
         return ('<patternmatcher patterns=%r>' % self._pats)
@@ -404,7 +404,7 @@ 
 
         self._pats, self.matchfn = _buildmatch(ctx, kindpats, '(?:/|$)',
                                                listsubrepos, root)
-        self._anypats = _anypats(kindpats)
+        self._prefix = _prefix(kindpats)
         roots, dirs = _rootsanddirs(kindpats)
         # roots are directories which are recursively included.
         self._roots = set(roots)
@@ -412,8 +412,7 @@ 
         self._dirs = set(dirs)
 
     def visitdir(self, dir):
-        if not self._anypats and dir in self._roots:
-            # The condition above is essentially self.prefix() for includes
+        if self._prefix and dir in self._roots:
             return 'all'
         return ('.' in self._roots or
                 dir in self._roots or
@@ -948,10 +947,13 @@ 
     filable = [kp for kp in kindpats if kp[0] not in ('rootfilesin',)]
     return _roots(filable)
 
-def _anypats(kindpats):
+def _prefix(kindpats):
+    '''Whether all the patterns match a prefix (i.e. recursively)'''
     for kind, pat, source in kindpats:
-        if kind in ('glob', 're', 'relglob', 'relre', 'set', 'rootfilesin'):
-            return True
+        assert kind not in ('listfile', 'listfile0', 'include', 'subinclude')
+        if kind not in ('path', 'relpath'):
+            return False
+    return True
 
 _commentre = None