Mercurial > hgsubversion
changeset 1401:70cb6ba038fa
maps: add ability to parse a regex or glob
This code is taken straight from mercurial's hgignore parser. With this patch
we can now understand 'syntax: glob' or 'syntax: re' lines as well as lines
that begin with 'glob:' or 're:'.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Mon, 24 Mar 2014 11:21:01 -0500 |
parents | 3e264851f879 |
children | 94eb844fd4ab |
files | hgsubversion/maps.py |
diffstat | 1 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -18,6 +18,7 @@ class BaseMap(dict): super(BaseMap, self).__init__() self._commentre = re.compile(r'((^|[^\\])(\\\\)*)#.*') + self.syntaxes = ('re', 'glob') # trickery: all subclasses have the same name as their file and config # names, e.g. AuthorMap is meta.authormap_file for the filename and @@ -111,6 +112,7 @@ class BaseMap(dict): self.meta.ui.debug('reading %s from %s\n' % (self.mapname , path)) f = open(path, 'r') + syntax = '' for number, line in enumerate(f): if writing: @@ -126,6 +128,20 @@ class BaseMap(dict): if not line: continue + if line.startswith('syntax:'): + s = line[7:].strip() + syntax = '' + if s in self.syntaxes: + syntax = s + continue + pat = syntax + for s in self.syntaxes: + if line.startswith(s + ':'): + pat = s + line = line[len(s) + 1:] + break + + # split on the first '=' try: src, dst = line.split('=', 1) except (IndexError, ValueError): @@ -137,6 +153,12 @@ class BaseMap(dict): src = src.strip() dst = dst.strip() + if pat != 're': + src = re.escape(src) + if pat == 'glob': + src = src.replace('\\*', '.*') + src = re.compile(src) + if src not in self: self.meta.ui.debug('adding %s to %s\n' % (src, self.mapname)) elif dst != self[src]: