comparison mercurial/ignore.py @ 18087:5712e3b12274

ignore: refactor ignore into two functions This prepares us for eventually being able to hash the list of patterns in use.
author Bryan O'Sullivan <bryano@fb.com>
date Mon, 17 Dec 2012 16:23:37 -0800
parents b35e3364f94a
children 52620e5db2f6
comparison
equal deleted inserted replaced
18086:739c88ff043c 18087:5712e3b12274
50 break 50 break
51 patterns.append(pat) 51 patterns.append(pat)
52 52
53 return patterns, warnings 53 return patterns, warnings
54 54
55 def readpats(root, files, warn):
56 '''return a dict mapping ignore-file-name to list-of-patterns'''
57
58 pats = {}
59 for f in files:
60 try:
61 pats[f] = []
62 fp = open(f)
63 pats[f], warnings = ignorepats(fp)
64 fp.close()
65 for warning in warnings:
66 warn("%s: %s\n" % (f, warning))
67 except IOError, inst:
68 if f != files[0]:
69 warn(_("skipping unreadable ignore file '%s': %s\n") %
70 (f, inst.strerror))
71 return pats
72
55 def ignore(root, files, warn): 73 def ignore(root, files, warn):
56 '''return matcher covering patterns in 'files'. 74 '''return matcher covering patterns in 'files'.
57 75
58 the files parsed for patterns include: 76 the files parsed for patterns include:
59 .hgignore in the repository root 77 .hgignore in the repository root
70 syntax: glob # defaults following lines to non-rooted globs 88 syntax: glob # defaults following lines to non-rooted globs
71 re:pattern # non-rooted regular expression 89 re:pattern # non-rooted regular expression
72 glob:pattern # non-rooted glob 90 glob:pattern # non-rooted glob
73 pattern # pattern of the current default type''' 91 pattern # pattern of the current default type'''
74 92
75 pats = {} 93 pats = readpats(root, files, warn)
76 for f in files:
77 try:
78 pats[f] = []
79 fp = open(f)
80 pats[f], warnings = ignorepats(fp)
81 fp.close()
82 for warning in warnings:
83 warn("%s: %s\n" % (f, warning))
84 except IOError, inst:
85 if f != files[0]:
86 warn(_("skipping unreadable ignore file '%s': %s\n") %
87 (f, inst.strerror))
88 94
89 allpats = [] 95 allpats = []
90 for patlist in pats.values(): 96 for patlist in pats.values():
91 allpats.extend(patlist) 97 allpats.extend(patlist)
92 if not allpats: 98 if not allpats: