[PATCH 3 of 4] match: enable 'relinclude:' syntax
Matt Mackall
mpm at selenic.com
Thu May 21 18:45:10 UTC 2015
On Wed, 2015-05-20 at 14:57 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham at fb.com>
> # Date 1431818705 25200
> # Sat May 16 16:25:05 2015 -0700
> # Node ID 3bbfdda372e8e4204a5440009bfbc9e81f2a93e9
> # Parent 28ac58249dbc906622e368357daadd4814f9c71c
> match: enable 'relinclude:' syntax
Forgot to amend.
> -import re
> +import os, re
Uh oh. We're slowly trying to purge all use of os.path from the core so
we can finally correctly support Unicode on Windows. Instead things
should use vfs, pathutil, util, or something else that encapsulates the
os.path calls.
We don't have a vfs handy here, so that's a bit of a nuisance..
> +def _expandsubinclude(kindpats, root):
> + '''Returns the list of subinclude matchers and the kindpats without the
> + subincludes in it.'''
Insofar as this is a "pure" function with no side effects, it'd actually
be better/faster/more convenient to do most of our poking at it with a
doctest rather than .t tests.
> + relmatchers = []
> + other = []
> +
> + for kind, pat, source in kindpats:
> + if kind == 'subinclude':
> + sourceroot = os.path.dirname(source)
> + path = os.path.join(sourceroot, pat)
Generally wrong as join uses os.sep, which will mean the matcher will
only work against the working copy on Windows. Won't matter for ignore
rules, but will otherwise be broken. Might want to "renormalize" with
util.pconvert().
> + newroot = os.path.dirname(path)
> + relmatcher = match(newroot, '', [], ['include:%s' % path])
> + prefix = os.path.relpath(newroot, root) + '/'
You probably want to use pathutil.canonpath?
> + relmatchers.append((prefix, relmatcher))
> + else:
> + other.append((kind, pat, source))
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list