Patchwork [2,of,2,V2] filterlang: add a small language to filter files

login
register
mail settings
Submitter Matt Harbison
Date Jan. 12, 2018, 2:07 a.m.
Message ID <op.zcphh8nj9lwrgf@envy>
Download mbox | patch
Permalink /patch/26692/
State Deferred, archived
Headers show

Comments

Matt Harbison - Jan. 12, 2018, 2:07 a.m.
On Thu, 11 Jan 2018 11:13:57 -0500, Matt Harbison <mharbison72@gmail.com>  
wrote:

>
>> On Jan 11, 2018, at 10:16 AM, Yuya Nishihara <yuya@tcha.org> wrote:
>>
>>> On Thu, 11 Jan 2018 00:17:39 -0500, Matt Harbison wrote:
>>> # HG changeset patch
>>> # User Matt Harbison <matt_harbison@yahoo.com>
>>> # Date 1515641014 18000
>>> #      Wed Jan 10 22:23:34 2018 -0500
>>> # Node ID 548e748cb3f4eea0aedb36a2b2e9fe3b77ffb263
>>> # Parent  962b2bdd70d094ce4bf9a8135495788166b04510
>>> filterlang: add a small language to filter files
>>
>>> Finally, I changed the extension operator from '.' to '*'.  This  
>>> matches how git
>>> tracks by extension, but might be slightly confusing here because '**'  
>>> recurses
>>> in Mercurial, but '*' usually doesn't.
>>
>> I prefer '**' or 'relglob:*' for fileset compatibility.
>
> Good idea.
>
>>> +        elif op == '/': # directory or full path test
>>> +            p = name[1:].rstrip('/') # prefix
>>> +            pl = len(p)
>>> +            f = lambda n, s: n.startswith(p) and (len(n) == pl or  
>>> n[pl] == '/')
>>> +            return f
>>
>> Perhaps this could be 'path:'.
>
> Good idea.

I ended up needing to add this to avoid a parse error.  The "*fileset*"  
tests run, but I'm not sure if this should be allowed for normal  
filesets.  The '/' operator works because it is in the globchars string.

              sym = program[s:pos]
Yuya Nishihara - Jan. 12, 2018, 12:05 p.m.
On Thu, 11 Jan 2018 21:07:10 -0500, Matt Harbison wrote:
> On Thu, 11 Jan 2018 11:13:57 -0500, Matt Harbison <mharbison72@gmail.com>  
> wrote:
> >> Perhaps this could be 'path:'.
> 
> I ended up needing to add this to avoid a parse error.  The "*fileset*"  
> tests run, but I'm not sure if this should be allowed for normal  
> filesets.  The '/' operator works because it is in the globchars string.
> 
> diff --git a/mercurial/fileset.py b/mercurial/fileset.py
> --- a/mercurial/fileset.py
> +++ b/mercurial/fileset.py
> @@ -72,13 +72,13 @@
>                   pos += 1
>               else:
>                   raise error.ParseError(_("unterminated string"), s)
> -        elif c.isalnum() or c in globchars or ord(c) > 127:
> +        elif c.isalnum() or c in globchars or ord(c) > 127 or c == ':':

Yep, ':' is reserved. We could instead add ':' operator to separate matcher
kind and pat, but I'm not sure which will be better. For now, we need quotes,
"<kind>:<pat>".

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -72,13 +72,13 @@ 
                  pos += 1
              else:
                  raise error.ParseError(_("unterminated string"), s)
-        elif c.isalnum() or c in globchars or ord(c) > 127:
+        elif c.isalnum() or c in globchars or ord(c) > 127 or c == ':':
              # gather up a symbol/keyword
              s = pos
              pos += 1
              while pos < l: # find end of symbol
                  d = program[pos]
-                if not (d.isalnum() or d in globchars or ord(d) > 127):
+                if not (d.isalnum() or d in globchars or ord(d) > 127 or  
d == ':'):
                      break
                  pos += 1