# HG changeset patch # User Matt Mackall # Date 2007-12-10 16:26:42 # Node ID 04c76f296ad6f8e32180d6c0fd3982e5faaff3cd # Parent 7dd5cf9d1e09476a9414577df863dc164a1e0688 ignore: fix up comment parsing - remove redundant newline bits - change loop to use regex - eliminate escaping of # in internal representation diff --git a/mercurial/ignore.py b/mercurial/ignore.py --- a/mercurial/ignore.py +++ b/mercurial/ignore.py @@ -6,18 +6,21 @@ # of the GNU General Public License, incorporated herein by reference. from i18n import _ -import util +import util, re + +_commentre = None def _parselines(fp): for line in fp: - if not line.endswith('\n'): - line += '\n' - escape = False - for i in xrange(len(line)): - if escape: escape = False - elif line[i] == '\\': escape = True - elif line[i] == '#': break - line = line[:i].rstrip() + if "#" in line: + global _commentre + if not _commentre: + _commentre = re.compile(r'((^|[^\\])(\\\\)*)#.*') + # remove comments prefixed by an even number of escapes + line = _commentre.sub(r'\1', line) + # fixup properly escaped comments that survived the above + line = line.replace("\\#", "#") + line = line.rstrip() if line: yield line