# HG changeset patch # User Sean Farley # Date 1395678060 18000 # Node ID c4055968f0301a07aabde83341d88dc601440346 # Parent f53a27e4e0d3d44947aacde86fabc6cf78b8f4cc maps: use regex for better comment handling This is copied straight from mercurial's hgignore parsing. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -2,6 +2,7 @@ import errno import os +import re from mercurial import util as hgutil from mercurial.node import bin, hex, nullid @@ -16,6 +17,8 @@ class BaseMap(dict): self.meta = meta super(BaseMap, self).__init__() + self._commentre = re.compile(r'((^|[^\\])(\\\\)*)#.*') + # trickery: all subclasses have the same name as their file and config # names, e.g. AuthorMap is meta.authormap_file for the filename and # 'authormap' for the config option @@ -46,8 +49,14 @@ class BaseMap(dict): if writing: writing.write(line) - line = line.split('#')[0] - if not line.strip(): + # strip out comments + if "#" in line: + # remove comments prefixed by an even number of escapes + line = self._commentre.sub(r'\1', line) + # fixup properly escaped comments that survived the above + line = line.replace("\\#", "#") + line = line.rstrip() + if not line: continue try: