84 return False |
84 return False |
85 return True |
85 return True |
86 |
86 |
87 def match(root, cwd, patterns, include=None, exclude=None, default='glob', |
87 def match(root, cwd, patterns, include=None, exclude=None, default='glob', |
88 exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None, |
88 exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None, |
89 badfn=None): |
89 badfn=None, icasefs=False): |
90 """build an object to match a set of file patterns |
90 """build an object to match a set of file patterns |
91 |
91 |
92 arguments: |
92 arguments: |
93 root - the canonical root of the tree you're matching against |
93 root - the canonical root of the tree you're matching against |
94 cwd - the current working directory, if relevant |
94 cwd - the current working directory, if relevant |
97 exclude - patterns to exclude (even if they are included) |
97 exclude - patterns to exclude (even if they are included) |
98 default - if a pattern in patterns has no explicit type, assume this one |
98 default - if a pattern in patterns has no explicit type, assume this one |
99 exact - patterns are actually filenames (include/exclude still apply) |
99 exact - patterns are actually filenames (include/exclude still apply) |
100 warn - optional function used for printing warnings |
100 warn - optional function used for printing warnings |
101 badfn - optional bad() callback for this matcher instead of the default |
101 badfn - optional bad() callback for this matcher instead of the default |
|
102 icasefs - make a matcher for wdir on case insensitive filesystems, which |
|
103 normalizes the given patterns to the case in the filesystem |
102 |
104 |
103 a pattern is one of: |
105 a pattern is one of: |
104 'glob:<glob>' - a glob relative to cwd |
106 'glob:<glob>' - a glob relative to cwd |
105 're:<regexp>' - a regular expression |
107 're:<regexp>' - a regular expression |
106 'path:<path>' - a path relative to repository root, which is matched |
108 'path:<path>' - a path relative to repository root, which is matched |
114 'include:<path>' - a file of patterns to read and include |
116 'include:<path>' - a file of patterns to read and include |
115 'subinclude:<path>' - a file of patterns to match against files under |
117 'subinclude:<path>' - a file of patterns to match against files under |
116 the same directory |
118 the same directory |
117 '<something>' - a pattern of the specified default type |
119 '<something>' - a pattern of the specified default type |
118 """ |
120 """ |
119 return matcher(root, cwd, _donormalize, patterns, include=include, |
121 normalize = _donormalize |
|
122 if icasefs: |
|
123 dirstate = ctx.repo().dirstate |
|
124 dsnormalize = dirstate.normalize |
|
125 |
|
126 def normalize(patterns, default, root, cwd, auditor, warn): |
|
127 kp = _donormalize(patterns, default, root, cwd, auditor, warn) |
|
128 kindpats = [] |
|
129 for kind, pats, source in kp: |
|
130 if kind not in ('re', 'relre'): # regex can't be normalized |
|
131 p = pats |
|
132 pats = dsnormalize(pats) |
|
133 |
|
134 # Preserve the original to handle a case only rename. |
|
135 if p != pats and p in dirstate: |
|
136 kindpats.append((kind, p, source)) |
|
137 |
|
138 kindpats.append((kind, pats, source)) |
|
139 return kindpats |
|
140 |
|
141 return matcher(root, cwd, normalize, patterns, include=include, |
120 exclude=exclude, default=default, exact=exact, |
142 exclude=exclude, default=default, exact=exact, |
121 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos, |
143 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos, |
122 warn=warn, badfn=badfn) |
144 warn=warn, badfn=badfn) |
123 |
|
124 def icasefsmatch(root, cwd, patterns, include=None, exclude=None, |
|
125 default='glob', auditor=None, ctx=None, |
|
126 listsubrepos=False, badfn=None): |
|
127 """A matcher for wdir on case insensitive filesystems, which normalizes the |
|
128 given patterns to the case in the filesystem. |
|
129 """ |
|
130 dirstate = ctx.repo().dirstate |
|
131 dsnormalize = dirstate.normalize |
|
132 |
|
133 def normalize(patterns, default, root, cwd, auditor, warn): |
|
134 kp = _donormalize(patterns, default, root, cwd, auditor, warn) |
|
135 kindpats = [] |
|
136 for kind, pats, source in kp: |
|
137 if kind not in ('re', 'relre'): # regex can't be normalized |
|
138 p = pats |
|
139 pats = dsnormalize(pats) |
|
140 |
|
141 # Preserve the original to handle a case only rename. |
|
142 if p != pats and p in dirstate: |
|
143 kindpats.append((kind, p, source)) |
|
144 |
|
145 kindpats.append((kind, pats, source)) |
|
146 return kindpats |
|
147 |
|
148 return matcher(root, cwd, normalize, patterns=patterns, include=include, |
|
149 exclude=exclude, default=default, auditor=auditor, ctx=ctx, |
|
150 listsubrepos=listsubrepos, badfn=badfn) |
|
151 |
145 |
152 def exact(root, cwd, files, badfn=None): |
146 def exact(root, cwd, files, badfn=None): |
153 return match(root, cwd, files, exact=True, badfn=badfn) |
147 return match(root, cwd, files, exact=True, badfn=badfn) |
154 |
148 |
155 def always(root, cwd): |
149 def always(root, cwd): |