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