comparison mercurial/ignore.py @ 5640:04c76f296ad6

ignore: fix up comment parsing - remove redundant newline bits - change loop to use regex - eliminate escaping of # in internal representation
author Matt Mackall <mpm@selenic.com>
date Mon, 10 Dec 2007 10:26:42 -0600
parents fae670ee6c6d
children 4dd7b28003d2
comparison
equal deleted inserted replaced
5639:7dd5cf9d1e09 5640:04c76f296ad6
4 # 4 #
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 from i18n import _ 8 from i18n import _
9 import util 9 import util, re
10
11 _commentre = None
10 12
11 def _parselines(fp): 13 def _parselines(fp):
12 for line in fp: 14 for line in fp:
13 if not line.endswith('\n'): 15 if "#" in line:
14 line += '\n' 16 global _commentre
15 escape = False 17 if not _commentre:
16 for i in xrange(len(line)): 18 _commentre = re.compile(r'((^|[^\\])(\\\\)*)#.*')
17 if escape: escape = False 19 # remove comments prefixed by an even number of escapes
18 elif line[i] == '\\': escape = True 20 line = _commentre.sub(r'\1', line)
19 elif line[i] == '#': break 21 # fixup properly escaped comments that survived the above
20 line = line[:i].rstrip() 22 line = line.replace("\\#", "#")
23 line = line.rstrip()
21 if line: 24 if line:
22 yield line 25 yield line
23 26
24 def ignore(root, files, warn): 27 def ignore(root, files, warn):
25 '''return the contents of .hgignore files as a list of patterns. 28 '''return the contents of .hgignore files as a list of patterns.