Show More
@@ -130,54 +130,79 b' def minusset(mctx, x, y):' | |||
|
130 | 130 | def listset(mctx, a, b): |
|
131 | 131 | raise error.ParseError(_("can't use a list in this context")) |
|
132 | 132 | |
|
133 | # symbols are callable like: | |
|
134 | # fun(mctx, x) | |
|
135 | # with: | |
|
136 | # mctx - current matchctx instance | |
|
137 | # x - argument in tree form | |
|
138 | symbols = {} | |
|
139 | ||
|
140 | def predicate(decl): | |
|
141 | """Return a decorator for fileset predicate function | |
|
142 | ||
|
143 | 'decl' argument is the declaration (including argument list like | |
|
144 | 'adds(pattern)') or the name (for internal use only) of predicate. | |
|
145 | """ | |
|
146 | def decorator(func): | |
|
147 | i = decl.find('(') | |
|
148 | if i > 0: | |
|
149 | name = decl[:i] | |
|
150 | else: | |
|
151 | name = decl | |
|
152 | symbols[name] = func | |
|
153 | if func.__doc__: | |
|
154 | func.__doc__ = "``%s``\n %s" % (decl, func.__doc__.strip()) | |
|
155 | return func | |
|
156 | return decorator | |
|
157 | ||
|
158 | @predicate('modified()') | |
|
133 | 159 | def modified(mctx, x): |
|
134 | """``modified()`` | |
|
135 | File that is modified according to :hg:`status`. | |
|
160 | """File that is modified according to :hg:`status`. | |
|
136 | 161 | """ |
|
137 | 162 | # i18n: "modified" is a keyword |
|
138 | 163 | getargs(x, 0, 0, _("modified takes no arguments")) |
|
139 | 164 | s = mctx.status().modified |
|
140 | 165 | return [f for f in mctx.subset if f in s] |
|
141 | 166 | |
|
167 | @predicate('added()') | |
|
142 | 168 | def added(mctx, x): |
|
143 | """``added()`` | |
|
144 | File that is added according to :hg:`status`. | |
|
169 | """File that is added according to :hg:`status`. | |
|
145 | 170 | """ |
|
146 | 171 | # i18n: "added" is a keyword |
|
147 | 172 | getargs(x, 0, 0, _("added takes no arguments")) |
|
148 | 173 | s = mctx.status().added |
|
149 | 174 | return [f for f in mctx.subset if f in s] |
|
150 | 175 | |
|
176 | @predicate('removed()') | |
|
151 | 177 | def removed(mctx, x): |
|
152 | """``removed()`` | |
|
153 | File that is removed according to :hg:`status`. | |
|
178 | """File that is removed according to :hg:`status`. | |
|
154 | 179 | """ |
|
155 | 180 | # i18n: "removed" is a keyword |
|
156 | 181 | getargs(x, 0, 0, _("removed takes no arguments")) |
|
157 | 182 | s = mctx.status().removed |
|
158 | 183 | return [f for f in mctx.subset if f in s] |
|
159 | 184 | |
|
185 | @predicate('deleted()') | |
|
160 | 186 | def deleted(mctx, x): |
|
161 | """``deleted()`` | |
|
162 | Alias for ``missing()``. | |
|
187 | """Alias for ``missing()``. | |
|
163 | 188 | """ |
|
164 | 189 | # i18n: "deleted" is a keyword |
|
165 | 190 | getargs(x, 0, 0, _("deleted takes no arguments")) |
|
166 | 191 | s = mctx.status().deleted |
|
167 | 192 | return [f for f in mctx.subset if f in s] |
|
168 | 193 | |
|
194 | @predicate('missing()') | |
|
169 | 195 | def missing(mctx, x): |
|
170 | """``missing()`` | |
|
171 | File that is missing according to :hg:`status`. | |
|
196 | """File that is missing according to :hg:`status`. | |
|
172 | 197 | """ |
|
173 | 198 | # i18n: "missing" is a keyword |
|
174 | 199 | getargs(x, 0, 0, _("missing takes no arguments")) |
|
175 | 200 | s = mctx.status().deleted |
|
176 | 201 | return [f for f in mctx.subset if f in s] |
|
177 | 202 | |
|
203 | @predicate('unknown()') | |
|
178 | 204 | def unknown(mctx, x): |
|
179 | """``unknown()`` | |
|
180 | File that is unknown according to :hg:`status`. These files will only be | |
|
205 | """File that is unknown according to :hg:`status`. These files will only be | |
|
181 | 206 | considered if this predicate is used. |
|
182 | 207 | """ |
|
183 | 208 | # i18n: "unknown" is a keyword |
@@ -185,9 +210,9 b' def unknown(mctx, x):' | |||
|
185 | 210 | s = mctx.status().unknown |
|
186 | 211 | return [f for f in mctx.subset if f in s] |
|
187 | 212 | |
|
213 | @predicate('ignored()') | |
|
188 | 214 | def ignored(mctx, x): |
|
189 | """``ignored()`` | |
|
190 | File that is ignored according to :hg:`status`. These files will only be | |
|
215 | """File that is ignored according to :hg:`status`. These files will only be | |
|
191 | 216 | considered if this predicate is used. |
|
192 | 217 | """ |
|
193 | 218 | # i18n: "ignored" is a keyword |
@@ -195,9 +220,9 b' def ignored(mctx, x):' | |||
|
195 | 220 | s = mctx.status().ignored |
|
196 | 221 | return [f for f in mctx.subset if f in s] |
|
197 | 222 | |
|
223 | @predicate('clean()') | |
|
198 | 224 | def clean(mctx, x): |
|
199 | """``clean()`` | |
|
200 | File that is clean according to :hg:`status`. | |
|
225 | """File that is clean according to :hg:`status`. | |
|
201 | 226 | """ |
|
202 | 227 | # i18n: "clean" is a keyword |
|
203 | 228 | getargs(x, 0, 0, _("clean takes no arguments")) |
@@ -226,33 +251,33 b' def getargs(x, min, max, err):' | |||
|
226 | 251 | raise error.ParseError(err) |
|
227 | 252 | return l |
|
228 | 253 | |
|
254 | @predicate('binary()') | |
|
229 | 255 | def binary(mctx, x): |
|
230 | """``binary()`` | |
|
231 | File that appears to be binary (contains NUL bytes). | |
|
256 | """File that appears to be binary (contains NUL bytes). | |
|
232 | 257 | """ |
|
233 | 258 | # i18n: "binary" is a keyword |
|
234 | 259 | getargs(x, 0, 0, _("binary takes no arguments")) |
|
235 | 260 | return [f for f in mctx.existing() if util.binary(mctx.ctx[f].data())] |
|
236 | 261 | |
|
262 | @predicate('exec()') | |
|
237 | 263 | def exec_(mctx, x): |
|
238 | """``exec()`` | |
|
239 | File that is marked as executable. | |
|
264 | """File that is marked as executable. | |
|
240 | 265 | """ |
|
241 | 266 | # i18n: "exec" is a keyword |
|
242 | 267 | getargs(x, 0, 0, _("exec takes no arguments")) |
|
243 | 268 | return [f for f in mctx.existing() if mctx.ctx.flags(f) == 'x'] |
|
244 | 269 | |
|
270 | @predicate('symlink()') | |
|
245 | 271 | def symlink(mctx, x): |
|
246 | """``symlink()`` | |
|
247 | File that is marked as a symlink. | |
|
272 | """File that is marked as a symlink. | |
|
248 | 273 | """ |
|
249 | 274 | # i18n: "symlink" is a keyword |
|
250 | 275 | getargs(x, 0, 0, _("symlink takes no arguments")) |
|
251 | 276 | return [f for f in mctx.existing() if mctx.ctx.flags(f) == 'l'] |
|
252 | 277 | |
|
278 | @predicate('resolved()') | |
|
253 | 279 | def resolved(mctx, x): |
|
254 | """``resolved()`` | |
|
255 | File that is marked resolved according to :hg:`resolve -l`. | |
|
280 | """File that is marked resolved according to :hg:`resolve -l`. | |
|
256 | 281 | """ |
|
257 | 282 | # i18n: "resolved" is a keyword |
|
258 | 283 | getargs(x, 0, 0, _("resolved takes no arguments")) |
@@ -261,9 +286,9 b' def resolved(mctx, x):' | |||
|
261 | 286 | ms = merge.mergestate.read(mctx.ctx.repo()) |
|
262 | 287 | return [f for f in mctx.subset if f in ms and ms[f] == 'r'] |
|
263 | 288 | |
|
289 | @predicate('unresolved()') | |
|
264 | 290 | def unresolved(mctx, x): |
|
265 | """``unresolved()`` | |
|
266 | File that is marked unresolved according to :hg:`resolve -l`. | |
|
291 | """File that is marked unresolved according to :hg:`resolve -l`. | |
|
267 | 292 | """ |
|
268 | 293 | # i18n: "unresolved" is a keyword |
|
269 | 294 | getargs(x, 0, 0, _("unresolved takes no arguments")) |
@@ -272,18 +297,18 b' def unresolved(mctx, x):' | |||
|
272 | 297 | ms = merge.mergestate.read(mctx.ctx.repo()) |
|
273 | 298 | return [f for f in mctx.subset if f in ms and ms[f] == 'u'] |
|
274 | 299 | |
|
300 | @predicate('hgignore()') | |
|
275 | 301 | def hgignore(mctx, x): |
|
276 | """``hgignore()`` | |
|
277 | File that matches the active .hgignore pattern. | |
|
302 | """File that matches the active .hgignore pattern. | |
|
278 | 303 | """ |
|
279 | 304 | # i18n: "hgignore" is a keyword |
|
280 | 305 | getargs(x, 0, 0, _("hgignore takes no arguments")) |
|
281 | 306 | ignore = mctx.ctx.repo().dirstate._ignore |
|
282 | 307 | return [f for f in mctx.subset if ignore(f)] |
|
283 | 308 | |
|
309 | @predicate('portable()') | |
|
284 | 310 | def portable(mctx, x): |
|
285 | """``portable()`` | |
|
286 | File that has a portable name. (This doesn't include filenames with case | |
|
311 | """File that has a portable name. (This doesn't include filenames with case | |
|
287 | 312 | collisions.) |
|
288 | 313 | """ |
|
289 | 314 | # i18n: "portable" is a keyword |
@@ -291,9 +316,9 b' def portable(mctx, x):' | |||
|
291 | 316 | checkwinfilename = util.checkwinfilename |
|
292 | 317 | return [f for f in mctx.subset if checkwinfilename(f) is None] |
|
293 | 318 | |
|
319 | @predicate('grep(regex)') | |
|
294 | 320 | def grep(mctx, x): |
|
295 | """``grep(regex)`` | |
|
296 | File contains the given regular expression. | |
|
321 | """File contains the given regular expression. | |
|
297 | 322 | """ |
|
298 | 323 | try: |
|
299 | 324 | # i18n: "grep" is a keyword |
@@ -318,9 +343,9 b' def _sizetomax(s):' | |||
|
318 | 343 | except ValueError: |
|
319 | 344 | raise error.ParseError(_("couldn't parse size: %s") % s) |
|
320 | 345 | |
|
346 | @predicate('size(expression)') | |
|
321 | 347 | def size(mctx, x): |
|
322 | """``size(expression)`` | |
|
323 | File size matches the given expression. Examples: | |
|
348 | """File size matches the given expression. Examples: | |
|
324 | 349 | |
|
325 | 350 | - 1k (files from 1024 to 2047 bytes) |
|
326 | 351 | - < 20k (files less than 20480 bytes) |
@@ -356,9 +381,9 b' def size(mctx, x):' | |||
|
356 | 381 | |
|
357 | 382 | return [f for f in mctx.existing() if m(mctx.ctx[f].size())] |
|
358 | 383 | |
|
384 | @predicate('encoding(name)') | |
|
359 | 385 | def encoding(mctx, x): |
|
360 | """``encoding(name)`` | |
|
361 | File can be successfully decoded with the given character | |
|
386 | """File can be successfully decoded with the given character | |
|
362 | 387 | encoding. May not be useful for encodings other than ASCII and |
|
363 | 388 | UTF-8. |
|
364 | 389 | """ |
@@ -379,9 +404,9 b' def encoding(mctx, x):' | |||
|
379 | 404 | |
|
380 | 405 | return s |
|
381 | 406 | |
|
407 | @predicate('eol(style)') | |
|
382 | 408 | def eol(mctx, x): |
|
383 | """``eol(style)`` | |
|
384 | File contains newlines of the given style (dos, unix, mac). Binary | |
|
409 | """File contains newlines of the given style (dos, unix, mac). Binary | |
|
385 | 410 | files are excluded, files with mixed line endings match multiple |
|
386 | 411 | styles. |
|
387 | 412 | """ |
@@ -402,9 +427,9 b' def eol(mctx, x):' | |||
|
402 | 427 | s.append(f) |
|
403 | 428 | return s |
|
404 | 429 | |
|
430 | @predicate('copied()') | |
|
405 | 431 | def copied(mctx, x): |
|
406 | """``copied()`` | |
|
407 | File that is recorded as being copied. | |
|
432 | """File that is recorded as being copied. | |
|
408 | 433 | """ |
|
409 | 434 | # i18n: "copied" is a keyword |
|
410 | 435 | getargs(x, 0, 0, _("copied takes no arguments")) |
@@ -415,9 +440,9 b' def copied(mctx, x):' | |||
|
415 | 440 | s.append(f) |
|
416 | 441 | return s |
|
417 | 442 | |
|
443 | @predicate('subrepo([pattern])') | |
|
418 | 444 | def subrepo(mctx, x): |
|
419 | """``subrepo([pattern])`` | |
|
420 | Subrepositories whose paths match the given pattern. | |
|
445 | """Subrepositories whose paths match the given pattern. | |
|
421 | 446 | """ |
|
422 | 447 | # i18n: "subrepo" is a keyword |
|
423 | 448 | getargs(x, 0, 1, _("subrepo takes at most one argument")) |
@@ -438,30 +463,6 b' def subrepo(mctx, x):' | |||
|
438 | 463 | else: |
|
439 | 464 | return [sub for sub in sstate] |
|
440 | 465 | |
|
441 | symbols = { | |
|
442 | 'added': added, | |
|
443 | 'binary': binary, | |
|
444 | 'clean': clean, | |
|
445 | 'copied': copied, | |
|
446 | 'deleted': deleted, | |
|
447 | 'encoding': encoding, | |
|
448 | 'eol': eol, | |
|
449 | 'exec': exec_, | |
|
450 | 'grep': grep, | |
|
451 | 'ignored': ignored, | |
|
452 | 'hgignore': hgignore, | |
|
453 | 'missing': missing, | |
|
454 | 'modified': modified, | |
|
455 | 'portable': portable, | |
|
456 | 'removed': removed, | |
|
457 | 'resolved': resolved, | |
|
458 | 'size': size, | |
|
459 | 'symlink': symlink, | |
|
460 | 'unknown': unknown, | |
|
461 | 'unresolved': unresolved, | |
|
462 | 'subrepo': subrepo, | |
|
463 | } | |
|
464 | ||
|
465 | 466 | methods = { |
|
466 | 467 | 'string': stringset, |
|
467 | 468 | 'symbol': stringset, |
General Comments 0
You need to be logged in to leave comments.
Login now