##// END OF EJS Templates
kill lonely docstring
Benoit Boissinot -
r5271:fae670ee default
parent child Browse files
Show More
@@ -1,93 +1,87 b''
1 1 # ignore.py - ignored file handling for mercurial
2 2 #
3 3 # Copyright 2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from i18n import _
9 9 import util
10 10
11 11 def _parselines(fp):
12 12 for line in fp:
13 13 if not line.endswith('\n'):
14 14 line += '\n'
15 15 escape = False
16 16 for i in xrange(len(line)):
17 17 if escape: escape = False
18 18 elif line[i] == '\\': escape = True
19 19 elif line[i] == '#': break
20 20 line = line[:i].rstrip()
21 21 if line:
22 22 yield line
23 23
24 24 def ignore(root, files, warn):
25 25 '''return the contents of .hgignore files as a list of patterns.
26 26
27 27 the files parsed for patterns include:
28 28 .hgignore in the repository root
29 29 any additional files specified in the [ui] section of ~/.hgrc
30 30
31 31 trailing white space is dropped.
32 32 the escape character is backslash.
33 33 comments start with #.
34 34 empty lines are skipped.
35 35
36 36 lines can be of the following formats:
37 37
38 38 syntax: regexp # defaults following lines to non-rooted regexps
39 39 syntax: glob # defaults following lines to non-rooted globs
40 40 re:pattern # non-rooted regular expression
41 41 glob:pattern # non-rooted glob
42 42 pattern # pattern of the current default type'''
43 43
44 44 syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:'}
45 45 pats = {}
46 46 for f in files:
47 47 try:
48 48 pats[f] = []
49 49 fp = open(f)
50 50 syntax = 'relre:'
51 51 for line in _parselines(fp):
52 52 if line.startswith('syntax:'):
53 53 s = line[7:].strip()
54 54 try:
55 55 syntax = syntaxes[s]
56 56 except KeyError:
57 57 warn(_("%s: ignoring invalid syntax '%s'\n") % (f, s))
58 58 continue
59 59 pat = syntax + line
60 60 for s, rels in syntaxes.items():
61 61 if line.startswith(rels):
62 62 pat = line
63 63 break
64 64 elif line.startswith(s+':'):
65 65 pat = rels + line[len(s)+1:]
66 66 break
67 67 pats[f].append(pat)
68 68 except IOError, inst:
69 69 if f != files[0]:
70 70 warn(_("skipping unreadable ignore file '%s': %s\n") %
71 71 (f, inst.strerror))
72 72
73 73 allpats = []
74 74 [allpats.extend(patlist) for patlist in pats.values()]
75 75 if not allpats:
76 76 return util.never
77 77
78 78 try:
79 79 files, ignorefunc, anypats = (
80 80 util.matcher(root, inc=allpats, src='.hgignore'))
81 81 except util.Abort:
82 82 # Re-raise an exception where the src is the right file
83 83 for f, patlist in pats.items():
84 84 files, ignorefunc, anypats = (
85 85 util.matcher(root, inc=patlist, src=f))
86 86
87 87 return ignorefunc
88
89
90 '''default match function used by dirstate and
91 localrepository. this honours the repository .hgignore file
92 and any other files specified in the [ui] section of .hgrc.'''
93
General Comments 0
You need to be logged in to leave comments. Login now