[MERGE] is_ignored improvements...

Wayne Davison wayned at samba.org
Fri May 19 08:18:13 BST 2006


On Fri, May 19, 2006 at 03:51:40PM +1000, Martin Pool wrote:
> So the ?! says "don't match anything with .*/ after this point", which
> is OK but I wonder if it'd be simpler or faster to just translate '*' to [^/]*.

I was wondering the same thing.  Note also that '?' would need to be
similarly translated into "[^/]".

While poking around, I saw that there is a python function named
glob_to_re that is in distutils.filelist.  This function takes the
fnmatch.translate output and tries to turn every non-backslash-escaped
dot into "[^/]".  Unfortunately, the regex-substitution that it uses does
not translate a dot after the matching of a literal backslash (e.g. the
regex "foo\\.*" would be unchanged) and it messes up if two dots in a row
are present (e.g. "foo??" -> "foo..$" -> "foo[^/].$").  It has this code:

    pattern_re = re.sub(r'(^|[^\\])\.', r'\1[^/]', pattern_re)

I think that the following regex should actually work properly:

    pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', r'\1[^/]', pattern_re)

This will translate any dot that has an even number of backslashes in
front it (including 0).  I'll look into reporting this bug to the python
folks.

..wayne..




More information about the bazaar mailing list