# HG changeset patch # User Matt Mackall # Date 1197304002 21600 # 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 -r 7dd5cf9d1e09 -r 04c76f296ad6 mercurial/ignore.py --- a/mercurial/ignore.py Mon Dec 10 10:24:47 2007 -0600 +++ b/mercurial/ignore.py Mon Dec 10 10:26:42 2007 -0600 @@ -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