# HG changeset patch # User Sean Farley # Date 1395678061 18000 # Node ID 70cb6ba038fa9fc7a12cb8887296158b5fa9463c # Parent 3e264851f87998a0e1a24c249e10eb4fad69ff1b 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:'. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- 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]: