annotate mercurial/fileset.py @ 38866:6371ab78c3b3

fileset: add phase to transform parsed tree This isn't strictly necessary, but I decided to just follow the strategy of the revset parsing.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 21 Jul 2018 16:11:36 +0900
parents 4fe8d1f077b8
children 48fc2a8af345
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14511
30506b894359 filesets: introduce basic fileset expression parser
Matt Mackall <mpm@selenic.com>
parents: 14509
diff changeset
1 # fileset.py - file set queries for mercurial
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
2 #
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
4 #
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
7
25938
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
8 from __future__ import absolute_import
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
9
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
10 import errno
20034
1e5b38a919dd cleanup: move stdlib imports to their own import statement
Augie Fackler <raf@durin42.com>
parents: 19470
diff changeset
11 import re
25938
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
12
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
13 from .i18n import _
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
14 from . import (
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
15 error,
38845
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
16 filesetlang,
35739
9eb5c400f488 fileset: move import of match module to top
Yuya Nishihara <yuya@tcha.org>
parents: 35692
diff changeset
17 match as matchmod,
25938
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
18 merge,
32556
1fb0a85fb20e py3: use pycompat.bytestr so that we don't get ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32331
diff changeset
19 pycompat,
28448
7108834c76a2 fileset: replace predicate by filesetpredicate of registrar (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28447
diff changeset
20 registrar,
31203
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
21 scmutil,
25938
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
22 util,
e194ada8d45f fileset: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25815
diff changeset
23 )
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36535
diff changeset
24 from .utils import (
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36535
diff changeset
25 stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36535
diff changeset
26 )
11275
c9ce8ecd6ca1 revset: introduce revset core
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
27
38845
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
28 # helpers for processing parsed tree
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
29 getsymbol = filesetlang.getsymbol
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
30 getstring = filesetlang.getstring
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
31 _getkindpat = filesetlang.getkindpat
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
32 getpattern = filesetlang.getpattern
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
33 getargs = filesetlang.getargs
38599
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
34
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
35 def getmatch(mctx, x):
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
36 if not x:
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
37 raise error.ParseError(_("missing argument"))
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
38 return methods[x[0]](mctx, *x[1:])
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
39
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
40 def stringmatch(mctx, x):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
41 return mctx.matcher([x])
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
42
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
43 def kindpatmatch(mctx, x, y):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
44 return stringmatch(mctx, _getkindpat(x, y, matchmod.allpatternkinds,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
45 _("pattern must be a string")))
35741
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35739
diff changeset
46
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
47 def andmatch(mctx, x, y):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
48 xm = getmatch(mctx, x)
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
49 ym = getmatch(mctx, y)
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
50 return matchmod.intersectmatchers(xm, ym)
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
51
38844
d82c4d42b615 fileset: flatten 'or' nodes to unnest unionmatchers
Yuya Nishihara <yuya@tcha.org>
parents: 38843
diff changeset
52 def ormatch(mctx, *xs):
d82c4d42b615 fileset: flatten 'or' nodes to unnest unionmatchers
Yuya Nishihara <yuya@tcha.org>
parents: 38843
diff changeset
53 ms = [getmatch(mctx, x) for x in xs]
d82c4d42b615 fileset: flatten 'or' nodes to unnest unionmatchers
Yuya Nishihara <yuya@tcha.org>
parents: 38843
diff changeset
54 return matchmod.unionmatcher(ms)
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
55
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
56 def notmatch(mctx, x):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
57 m = getmatch(mctx, x)
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
58 return mctx.predicate(lambda f: not m(f), predrepr=('<not %r>', m))
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
59
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
60 def minusmatch(mctx, x, y):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
61 xm = getmatch(mctx, x)
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
62 ym = getmatch(mctx, y)
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
63 return matchmod.differencematcher(xm, ym)
17363
5d9e2031c0b1 fileset: actually implement 'minusset'
Patrick Mezard <patrick@mezard.eu>
parents: 16443
diff changeset
64
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
65 def negatematch(mctx, x):
35692
a62b08f6626b fileset: do not crash by unary negate operation
Yuya Nishihara <yuya@tcha.org>
parents: 35691
diff changeset
66 raise error.ParseError(_("can't use negate operator in this context"))
a62b08f6626b fileset: do not crash by unary negate operation
Yuya Nishihara <yuya@tcha.org>
parents: 35691
diff changeset
67
38843
4dc498d61d86 fileset: flatten arguments list
Yuya Nishihara <yuya@tcha.org>
parents: 38813
diff changeset
68 def listmatch(mctx, *xs):
27518
737ffdabbde9 fileset: add hint for list error to use or
timeless <timeless@mozdev.org>
parents: 27464
diff changeset
69 raise error.ParseError(_("can't use a list in this context"),
38850
4fe8d1f077b8 help: add quotes to a few commands we point to
Martin von Zweigbergk <martinvonz@google.com>
parents: 38845
diff changeset
70 hint=_('see \'hg help "filesets.x or y"\''))
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
71
38599
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
72 def func(mctx, a, b):
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
73 funcname = getsymbol(a)
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
74 if funcname in symbols:
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
75 return symbols[funcname](mctx, b)
38599
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
76
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
77 keep = lambda fn: getattr(fn, '__doc__', None) is not None
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
78
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
79 syms = [s for (s, fn) in symbols.items() if keep(fn)]
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
80 raise error.UnknownIdentifier(funcname, syms)
d046bf37f1ba fileset: move helper functions to top
Yuya Nishihara <yuya@tcha.org>
parents: 38420
diff changeset
81
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
82 # symbols are callable like:
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
83 # fun(mctx, x)
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
84 # with:
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
85 # mctx - current matchctx instance
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
86 # x - argument in tree form
38845
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
87 symbols = filesetlang.symbols
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
88
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
89 # filesets using matchctx.status()
27463
a8afdc5a7885 fileset: use set instead of list to mark predicates for efficiency (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27462
diff changeset
90 _statuscallers = set()
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
91
28448
7108834c76a2 fileset: replace predicate by filesetpredicate of registrar (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28447
diff changeset
92 predicate = registrar.filesetpredicate()
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
93
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
94 @predicate('modified()', callstatus=True)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
95 def modified(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
96 """File that is modified according to :hg:`status`.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
97 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
98 # i18n: "modified" is a keyword
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
99 getargs(x, 0, 0, _("modified takes no arguments"))
31702
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31264
diff changeset
100 s = set(mctx.status().modified)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
101 return mctx.predicate(s.__contains__, predrepr='modified')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
102
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
103 @predicate('added()', callstatus=True)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
104 def added(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
105 """File that is added according to :hg:`status`.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
106 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
107 # i18n: "added" is a keyword
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
108 getargs(x, 0, 0, _("added takes no arguments"))
31702
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31264
diff changeset
109 s = set(mctx.status().added)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
110 return mctx.predicate(s.__contains__, predrepr='added')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
111
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
112 @predicate('removed()', callstatus=True)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
113 def removed(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
114 """File that is removed according to :hg:`status`.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
115 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
116 # i18n: "removed" is a keyword
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
117 getargs(x, 0, 0, _("removed takes no arguments"))
31702
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31264
diff changeset
118 s = set(mctx.status().removed)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
119 return mctx.predicate(s.__contains__, predrepr='removed')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
120
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
121 @predicate('deleted()', callstatus=True)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
122 def deleted(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
123 """Alias for ``missing()``.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
124 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
125 # i18n: "deleted" is a keyword
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
126 getargs(x, 0, 0, _("deleted takes no arguments"))
31702
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31264
diff changeset
127 s = set(mctx.status().deleted)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
128 return mctx.predicate(s.__contains__, predrepr='deleted')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
129
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
130 @predicate('missing()', callstatus=True)
27024
ceef5fb14872 fileset: add missing() predicate (issue4925)
liscju <piotr.listkiewicz@gmail.com>
parents: 26995
diff changeset
131 def missing(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
132 """File that is missing according to :hg:`status`.
27024
ceef5fb14872 fileset: add missing() predicate (issue4925)
liscju <piotr.listkiewicz@gmail.com>
parents: 26995
diff changeset
133 """
ceef5fb14872 fileset: add missing() predicate (issue4925)
liscju <piotr.listkiewicz@gmail.com>
parents: 26995
diff changeset
134 # i18n: "missing" is a keyword
ceef5fb14872 fileset: add missing() predicate (issue4925)
liscju <piotr.listkiewicz@gmail.com>
parents: 26995
diff changeset
135 getargs(x, 0, 0, _("missing takes no arguments"))
31702
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31264
diff changeset
136 s = set(mctx.status().deleted)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
137 return mctx.predicate(s.__contains__, predrepr='deleted')
27024
ceef5fb14872 fileset: add missing() predicate (issue4925)
liscju <piotr.listkiewicz@gmail.com>
parents: 26995
diff changeset
138
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
139 @predicate('unknown()', callstatus=True)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
140 def unknown(mctx, x):
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
141 """File that is unknown according to :hg:`status`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
142 # i18n: "unknown" is a keyword
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
143 getargs(x, 0, 0, _("unknown takes no arguments"))
31702
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31264
diff changeset
144 s = set(mctx.status().unknown)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
145 return mctx.predicate(s.__contains__, predrepr='unknown')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
146
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
147 @predicate('ignored()', callstatus=True)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
148 def ignored(mctx, x):
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
149 """File that is ignored according to :hg:`status`."""
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
150 # i18n: "ignored" is a keyword
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
151 getargs(x, 0, 0, _("ignored takes no arguments"))
31702
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31264
diff changeset
152 s = set(mctx.status().ignored)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
153 return mctx.predicate(s.__contains__, predrepr='ignored')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
154
27461
afa76585c955 fileset: use decorator to mark a predicate as "status caller"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27460
diff changeset
155 @predicate('clean()', callstatus=True)
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
156 def clean(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
157 """File that is clean according to :hg:`status`.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
158 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
159 # i18n: "clean" is a keyword
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
160 getargs(x, 0, 0, _("clean takes no arguments"))
31702
992882cef7e1 fileset: perform membership test against set for status queries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31264
diff changeset
161 s = set(mctx.status().clean)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
162 return mctx.predicate(s.__contains__, predrepr='clean')
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
163
38686
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
164 @predicate('tracked()')
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
165 def tracked(mctx, x):
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
166 """File that is under Mercurial control."""
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
167 # i18n: "tracked" is a keyword
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
168 getargs(x, 0, 0, _("tracked takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
169 return mctx.predicate(mctx.ctx.__contains__, predrepr='tracked')
38686
131aae58a316 fileset: add "tracked()" to explicitly select files in the revision
Yuya Nishihara <yuya@tcha.org>
parents: 38685
diff changeset
170
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
171 @predicate('binary()')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
172 def binary(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
173 """File that appears to be binary (contains NUL bytes).
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
174 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
175 # i18n: "binary" is a keyword
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
176 getargs(x, 0, 0, _("binary takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
177 return mctx.fpredicate(lambda fctx: fctx.isbinary(),
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
178 predrepr='binary', cache=True)
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
179
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
180 @predicate('exec()')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
181 def exec_(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
182 """File that is marked as executable.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
183 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
184 # i18n: "exec" is a keyword
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
185 getargs(x, 0, 0, _("exec takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
186 ctx = mctx.ctx
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
187 return mctx.predicate(lambda f: ctx.flags(f) == 'x', predrepr='exec')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
188
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
189 @predicate('symlink()')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
190 def symlink(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
191 """File that is marked as a symlink.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
192 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
193 # i18n: "symlink" is a keyword
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
194 getargs(x, 0, 0, _("symlink takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
195 ctx = mctx.ctx
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
196 return mctx.predicate(lambda f: ctx.flags(f) == 'l', predrepr='symlink')
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
197
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
198 @predicate('resolved()')
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
199 def resolved(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
200 """File that is marked resolved according to :hg:`resolve -l`.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
201 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
202 # i18n: "resolved" is a keyword
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
203 getargs(x, 0, 0, _("resolved takes no arguments"))
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
204 if mctx.ctx.rev() is not None:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
205 return mctx.never()
26995
d5a6be56970b fileset: switch to mergestate.read()
Siddharth Agarwal <sid0@fb.com>
parents: 26587
diff changeset
206 ms = merge.mergestate.read(mctx.ctx.repo())
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
207 return mctx.predicate(lambda f: f in ms and ms[f] == 'r',
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
208 predrepr='resolved')
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
209
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
210 @predicate('unresolved()')
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
211 def unresolved(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
212 """File that is marked unresolved according to :hg:`resolve -l`.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
213 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
214 # i18n: "unresolved" is a keyword
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
215 getargs(x, 0, 0, _("unresolved takes no arguments"))
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
216 if mctx.ctx.rev() is not None:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
217 return mctx.never()
26995
d5a6be56970b fileset: switch to mergestate.read()
Siddharth Agarwal <sid0@fb.com>
parents: 26587
diff changeset
218 ms = merge.mergestate.read(mctx.ctx.repo())
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
219 return mctx.predicate(lambda f: f in ms and ms[f] == 'u',
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
220 predrepr='unresolved')
14679
e141e1cee0cc fileset: add resolved and unresolved predicates
Matt Mackall <mpm@selenic.com>
parents: 14678
diff changeset
221
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
222 @predicate('hgignore()')
14680
49af5fa3809b fileset: add hgignore
Matt Mackall <mpm@selenic.com>
parents: 14679
diff changeset
223 def hgignore(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
224 """File that matches the active .hgignore pattern.
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
225 """
23113
c2dd79ad99cb i18n: add i18n comment to error messages of filesets predicates
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22924
diff changeset
226 # i18n: "hgignore" is a keyword
14680
49af5fa3809b fileset: add hgignore
Matt Mackall <mpm@selenic.com>
parents: 14679
diff changeset
227 getargs(x, 0, 0, _("hgignore takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
228 return mctx.ctx.repo().dirstate._ignore
14680
49af5fa3809b fileset: add hgignore
Matt Mackall <mpm@selenic.com>
parents: 14679
diff changeset
229
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
230 @predicate('portable()')
24408
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
231 def portable(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
232 """File that has a portable name. (This doesn't include filenames with case
24408
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
233 collisions.)
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
234 """
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
235 # i18n: "portable" is a keyword
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
236 getargs(x, 0, 0, _("portable takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
237 return mctx.predicate(lambda f: util.checkwinfilename(f) is None,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
238 predrepr='portable')
24408
caa6b6c65dc3 fileset: add a fileset for portable filenames
Siddharth Agarwal <sid0@fb.com>
parents: 24334
diff changeset
239
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
240 @predicate('grep(regex)')
14682
8785fd757077 fileset: add grep predicate
Matt Mackall <mpm@selenic.com>
parents: 14681
diff changeset
241 def grep(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
242 """File contains the given regular expression.
14682
8785fd757077 fileset: add grep predicate
Matt Mackall <mpm@selenic.com>
parents: 14681
diff changeset
243 """
17368
01cc267fc105 fileset: do not traceback on invalid grep pattern
Patrick Mezard <patrick@mezard.eu>
parents: 17367
diff changeset
244 try:
01cc267fc105 fileset: do not traceback on invalid grep pattern
Patrick Mezard <patrick@mezard.eu>
parents: 17367
diff changeset
245 # i18n: "grep" is a keyword
01cc267fc105 fileset: do not traceback on invalid grep pattern
Patrick Mezard <patrick@mezard.eu>
parents: 17367
diff changeset
246 r = re.compile(getstring(x, _("grep requires a pattern")))
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25654
diff changeset
247 except re.error as e:
38116
5f2dc1b71cf1 py3: use utils.stringutil.forcebytestr to convert error to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37259
diff changeset
248 raise error.ParseError(_('invalid match pattern: %s') %
5f2dc1b71cf1 py3: use utils.stringutil.forcebytestr to convert error to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37259
diff changeset
249 stringutil.forcebytestr(e))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
250 return mctx.fpredicate(lambda fctx: r.search(fctx.data()),
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
251 predrepr=('grep(%r)', r.pattern), cache=True)
14682
8785fd757077 fileset: add grep predicate
Matt Mackall <mpm@selenic.com>
parents: 14681
diff changeset
252
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
253 def _sizetomax(s):
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
254 try:
25925
23c4589fc678 filesets: ignore unit case in size() predicate for single value
Anton Shestakov <av6@dwimlabs.net>
parents: 25815
diff changeset
255 s = s.strip().lower()
19194
1d08df65cd3c util: migrate fileset._sizetoint to util.sizetoint
Bryan O'Sullivan <bryano@fb.com>
parents: 18842
diff changeset
256 for k, v in util._sizeunits:
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
257 if s.endswith(k):
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
258 # max(4k) = 5k - 1, max(4.5k) = 4.6k - 1
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
259 n = s[:-len(k)]
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
260 inc = 1.0
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
261 if "." in n:
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
262 inc /= 10 ** len(n.split(".")[1])
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
263 return int((float(n) + inc) * v) - 1
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
264 # no extension, this is a precise value
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
265 return int(s)
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
266 except ValueError:
14716
552329013bac fileset: use ParseError pos field correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14701
diff changeset
267 raise error.ParseError(_("couldn't parse size: %s") % s)
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
268
38687
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
269 def sizematcher(expr):
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
270 """Return a function(size) -> bool from the ``size()`` expression"""
38687
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
271 expr = expr.strip()
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
272 if '-' in expr: # do we have a range?
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
273 a, b = expr.split('-', 1)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
274 a = util.sizetoint(a)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
275 b = util.sizetoint(b)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
276 return lambda x: x >= a and x <= b
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
277 elif expr.startswith("<="):
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
278 a = util.sizetoint(expr[2:])
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
279 return lambda x: x <= a
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
280 elif expr.startswith("<"):
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
281 a = util.sizetoint(expr[1:])
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
282 return lambda x: x < a
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
283 elif expr.startswith(">="):
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
284 a = util.sizetoint(expr[2:])
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
285 return lambda x: x >= a
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
286 elif expr.startswith(">"):
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
287 a = util.sizetoint(expr[1:])
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
288 return lambda x: x > a
36535
db33c5bc781f fileset: drop bad "elif:" trying to check invalid size expression
Yuya Nishihara <yuya@tcha.org>
parents: 36503
diff changeset
289 else:
35615
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
290 a = util.sizetoint(expr)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
291 b = _sizetomax(expr)
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
292 return lambda x: x >= a and x <= b
0e369eca888f fileset: split the logic for matching a size expression to a separate method
Matt Harbison <matt_harbison@yahoo.com>
parents: 32556
diff changeset
293
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
294 @predicate('size(expression)')
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
295 def size(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
296 """File size matches the given expression. Examples:
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
297
29991
d532ef155b0e help: clarify quotes are needed for filesets.size expressions
timeless <timeless@mozdev.org>
parents: 28448
diff changeset
298 - size('1k') - files from 1024 to 2047 bytes
d532ef155b0e help: clarify quotes are needed for filesets.size expressions
timeless <timeless@mozdev.org>
parents: 28448
diff changeset
299 - size('< 20k') - files less than 20480 bytes
d532ef155b0e help: clarify quotes are needed for filesets.size expressions
timeless <timeless@mozdev.org>
parents: 28448
diff changeset
300 - size('>= .5MB') - files at least 524288 bytes
d532ef155b0e help: clarify quotes are needed for filesets.size expressions
timeless <timeless@mozdev.org>
parents: 28448
diff changeset
301 - size('4k - 1MB') - files from 4096 bytes to 1048576 bytes
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
302 """
38687
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
303 # i18n: "size" is a keyword
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
304 expr = getstring(x, _("size requires an expression"))
1500cbe22d53 fileset: parse argument of size() by predicate function
Yuya Nishihara <yuya@tcha.org>
parents: 38686
diff changeset
305 m = sizematcher(expr)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
306 return mctx.fpredicate(lambda fctx: m(fctx.size()),
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
307 predrepr=('size(%r)', expr), cache=True)
14683
281102f37b24 fileset: add size() predicate
Matt Mackall <mpm@selenic.com>
parents: 14682
diff changeset
308
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
309 @predicate('encoding(name)')
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
310 def encoding(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
311 """File can be successfully decoded with the given character
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
312 encoding. May not be useful for encodings other than ASCII and
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
313 UTF-8.
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
314 """
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
315
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
316 # i18n: "encoding" is a keyword
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
317 enc = getstring(x, _("encoding requires an encoding name"))
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
318
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
319 def encp(fctx):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
320 d = fctx.data()
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
321 try:
38334
5cb39a368c80 py3: cast bytes encoding name to str in fileset.py
Yuya Nishihara <yuya@tcha.org>
parents: 38116
diff changeset
322 d.decode(pycompat.sysstr(enc))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
323 return True
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
324 except LookupError:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26233
diff changeset
325 raise error.Abort(_("unknown encoding '%s'") % enc)
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
326 except UnicodeDecodeError:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
327 return False
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
328
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
329 return mctx.fpredicate(encp, predrepr=('encoding(%r)', enc), cache=True)
14684
87b9d6a7d807 fileset: add encoding() predicate
Matt Mackall <mpm@selenic.com>
parents: 14683
diff changeset
330
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
331 @predicate('eol(style)')
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
332 def eol(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
333 """File contains newlines of the given style (dos, unix, mac). Binary
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
334 files are excluded, files with mixed line endings match multiple
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
335 styles.
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
336 """
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
337
28056
4f8ced23345e fileset: fix copy/paste in eol() error message
Matt Harbison <matt_harbison@yahoo.com>
parents: 27518
diff changeset
338 # i18n: "eol" is a keyword
4f8ced23345e fileset: fix copy/paste in eol() error message
Matt Harbison <matt_harbison@yahoo.com>
parents: 27518
diff changeset
339 enc = getstring(x, _("eol requires a style name"))
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
340
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
341 def eolp(fctx):
38420
235d0bc11e1d fileset: use filectx.isbinary() to filter out binaries in eol()
Matt Harbison <matt_harbison@yahoo.com>
parents: 38335
diff changeset
342 if fctx.isbinary():
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
343 return False
38420
235d0bc11e1d fileset: use filectx.isbinary() to filter out binaries in eol()
Matt Harbison <matt_harbison@yahoo.com>
parents: 38335
diff changeset
344 d = fctx.data()
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
345 if (enc == 'dos' or enc == 'win') and '\r\n' in d:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
346 return True
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
347 elif enc == 'unix' and re.search('(?<!\r)\n', d):
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
348 return True
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
349 elif enc == 'mac' and re.search('\r(?!\n)', d):
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
350 return True
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
351 return False
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
352 return mctx.fpredicate(eolp, predrepr=('eol(%r)', enc), cache=True)
18842
3ce3f2b059a1 filesets: add eol predicate
Matt Mackall <mpm@selenic.com>
parents: 18364
diff changeset
353
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
354 @predicate('copied()')
14685
394121d9f4fc fileset: add copied predicate
Matt Mackall <mpm@selenic.com>
parents: 14684
diff changeset
355 def copied(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
356 """File that is recorded as being copied.
14685
394121d9f4fc fileset: add copied predicate
Matt Mackall <mpm@selenic.com>
parents: 14684
diff changeset
357 """
14785
0f0bd4d028d3 fileset: add i18n hints for keywords
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 14718
diff changeset
358 # i18n: "copied" is a keyword
14718
0c81948636f3 fileset: copied takes no arguments
Mads Kiilerich <mads@kiilerich.com>
parents: 14717
diff changeset
359 getargs(x, 0, 0, _("copied takes no arguments"))
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
360 def copiedp(fctx):
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
361 p = fctx.parents()
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
362 return p and p[0].path() != fctx.path()
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
363 return mctx.fpredicate(copiedp, predrepr='copied', cache=True)
14685
394121d9f4fc fileset: add copied predicate
Matt Mackall <mpm@selenic.com>
parents: 14684
diff changeset
364
31203
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
365 @predicate('revs(revs, pattern)')
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
366 def revs(mctx, x):
31264
2140e12d3258 fileset: drop false function signatures from revs() and status() docs
Yuya Nishihara <yuya@tcha.org>
parents: 31205
diff changeset
367 """Evaluate set in the specified revisions. If the revset match multiple
2140e12d3258 fileset: drop false function signatures from revs() and status() docs
Yuya Nishihara <yuya@tcha.org>
parents: 31205
diff changeset
368 revs, this will return file matching pattern in any of the revision.
31203
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
369 """
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
370 # i18n: "revs" is a keyword
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
371 r, x = getargs(x, 2, 2, _("revs takes two arguments"))
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
372 # i18n: "revs" is a keyword
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
373 revspec = getstring(r, _("first argument to revs must be a revision"))
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
374 repo = mctx.ctx.repo()
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
375 revs = scmutil.revrange(repo, [revspec])
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
376
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
377 matchers = []
31203
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
378 for r in revs:
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
379 ctx = repo[r]
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
380 matchers.append(getmatch(mctx.switch(ctx, _buildstatus(ctx, x)), x))
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
381 if not matchers:
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
382 return mctx.never()
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
383 if len(matchers) == 1:
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
384 return matchers[0]
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
385 return matchmod.unionmatcher(matchers)
31203
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
386
31205
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
387 @predicate('status(base, rev, pattern)')
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
388 def status(mctx, x):
31264
2140e12d3258 fileset: drop false function signatures from revs() and status() docs
Yuya Nishihara <yuya@tcha.org>
parents: 31205
diff changeset
389 """Evaluate predicate using status change between ``base`` and
31205
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
390 ``rev``. Examples:
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
391
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
392 - ``status(3, 7, added())`` - matches files added from "3" to "7"
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
393 """
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
394 repo = mctx.ctx.repo()
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
395 # i18n: "status" is a keyword
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
396 b, r, x = getargs(x, 3, 3, _("status takes three arguments"))
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
397 # i18n: "status" is a keyword
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
398 baseerr = _("first argument to status must be a revision")
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
399 baserevspec = getstring(b, baseerr)
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
400 if not baserevspec:
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
401 raise error.ParseError(baseerr)
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
402 reverr = _("second argument to status must be a revision")
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
403 revspec = getstring(r, reverr)
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
404 if not revspec:
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
405 raise error.ParseError(reverr)
37259
f290f130d7fc fileset: use context-returning revpair()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37253
diff changeset
406 basectx, ctx = scmutil.revpair(repo, [baserevspec, revspec])
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
407 return getmatch(mctx.switch(ctx, _buildstatus(ctx, x, basectx=basectx)), x)
31205
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
408
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
409 @predicate('subrepo([pattern])')
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
410 def subrepo(mctx, x):
27460
11286ac374f3 fileset: use decorator to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27459
diff changeset
411 """Subrepositories whose paths match the given pattern.
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
412 """
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
413 # i18n: "subrepo" is a keyword
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
414 getargs(x, 0, 1, _("subrepo takes at most one argument"))
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
415 ctx = mctx.ctx
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
416 sstate = ctx.substate
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
417 if x:
35741
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35739
diff changeset
418 pat = getpattern(x, matchmod.allpatternkinds,
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35739
diff changeset
419 # i18n: "subrepo" is a keyword
73432eee0ac4 fileset: add kind:pat operator
Yuya Nishihara <yuya@tcha.org>
parents: 35739
diff changeset
420 _("subrepo requires a pattern or no arguments"))
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
421 fast = not matchmod.patkind(pat)
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
422 if fast:
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
423 def m(s):
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
424 return (s == pat)
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
425 else:
24334
eda2f36889b5 fileset: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24218
diff changeset
426 m = matchmod.match(ctx.repo().root, '', [pat], ctx=ctx)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
427 return mctx.predicate(lambda f: f in sstate and m(f),
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
428 predrepr=('subrepo(%r)', pat))
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
429 else:
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
430 return mctx.predicate(sstate.__contains__, predrepr='subrepo')
16443
9e02e032b522 fileset: add "subrepo" fileset symbol
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 15963
diff changeset
431
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
432 methods = {
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
433 'string': stringmatch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
434 'symbol': stringmatch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
435 'kindpat': kindpatmatch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
436 'and': andmatch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
437 'or': ormatch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
438 'minus': minusmatch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
439 'negate': negatematch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
440 'list': listmatch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
441 'group': getmatch,
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
442 'not': notmatch,
14676
e80fa502b8cf fileset: add some basic predicates
Matt Mackall <mpm@selenic.com>
parents: 14673
diff changeset
443 'func': func,
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
444 }
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
445
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
446 class matchctx(object):
38691
370ff3e34160 fileset: remove subset and unused filtering functions from matchctx
Yuya Nishihara <yuya@tcha.org>
parents: 38690
diff changeset
447 def __init__(self, ctx, status=None, badfn=None):
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
448 self.ctx = ctx
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
449 self._status = status
38614
5cbcbe51d38d fileset: pass in badfn to inner matchers
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
450 self._badfn = badfn
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
451
14677
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
452 def status(self):
2a758ffc821e fileset: add support for file status predicates
Matt Mackall <mpm@selenic.com>
parents: 14676
diff changeset
453 return self._status
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
454
14673
b0566467c492 fileset: drop matchfn
Matt Mackall <mpm@selenic.com>
parents: 14554
diff changeset
455 def matcher(self, patterns):
38614
5cbcbe51d38d fileset: pass in badfn to inner matchers
Yuya Nishihara <yuya@tcha.org>
parents: 38613
diff changeset
456 return self.ctx.match(patterns, badfn=self._badfn)
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
457
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
458 def predicate(self, predfn, predrepr=None, cache=False):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
459 """Create a matcher to select files by predfn(filename)"""
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
460 if cache:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
461 predfn = util.cachefunc(predfn)
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
462 repo = self.ctx.repo()
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
463 return matchmod.predicatematcher(repo.root, repo.getcwd(), predfn,
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
464 predrepr=predrepr, badfn=self._badfn)
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
465
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
466 def fpredicate(self, predfn, predrepr=None, cache=False):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
467 """Create a matcher to select files by predfn(fctx) at the current
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
468 revision
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
469
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
470 Missing files are ignored.
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
471 """
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
472 ctx = self.ctx
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
473 if ctx.rev() is None:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
474 def fctxpredfn(f):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
475 try:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
476 fctx = ctx[f]
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
477 except error.LookupError:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
478 return False
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
479 try:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
480 fctx.audit()
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
481 except error.Abort:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
482 return False
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
483 try:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
484 return predfn(fctx)
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
485 except (IOError, OSError) as e:
38758
774f92710a81 fileset: suppress EACCES while reading arbitrary paths via filectx API
Yuya Nishihara <yuya@tcha.org>
parents: 38692
diff changeset
486 # open()-ing a directory fails with EACCES on Windows
774f92710a81 fileset: suppress EACCES while reading arbitrary paths via filectx API
Yuya Nishihara <yuya@tcha.org>
parents: 38692
diff changeset
487 if e.errno in (errno.ENOENT, errno.EACCES, errno.ENOTDIR,
774f92710a81 fileset: suppress EACCES while reading arbitrary paths via filectx API
Yuya Nishihara <yuya@tcha.org>
parents: 38692
diff changeset
488 errno.EISDIR):
38684
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
489 return False
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
490 raise
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
491 else:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
492 def fctxpredfn(f):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
493 try:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
494 fctx = ctx[f]
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
495 except error.LookupError:
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
496 return False
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
497 return predfn(fctx)
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
498 return self.predicate(fctxpredfn, predrepr=predrepr, cache=cache)
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
499
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
500 def never(self):
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
501 """Create a matcher to select nothing"""
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
502 repo = self.ctx.repo()
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
503 return matchmod.nevermatcher(repo.root, repo.getcwd(),
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
504 badfn=self._badfn)
07b551a4df44 fileset: add helpers to make predicatematcher and nevermatcher
Yuya Nishihara <yuya@tcha.org>
parents: 38614
diff changeset
505
31202
951d95b13487 fileset: add function to switch revision where fileset will be evaluated
Yuya Nishihara <yuya@tcha.org>
parents: 31201
diff changeset
506 def switch(self, ctx, status=None):
38691
370ff3e34160 fileset: remove subset and unused filtering functions from matchctx
Yuya Nishihara <yuya@tcha.org>
parents: 38690
diff changeset
507 return matchctx(ctx, status, self._badfn)
14551
68d814a3cefd fileset: basic pattern and boolean support
Matt Mackall <mpm@selenic.com>
parents: 14513
diff changeset
508
31202
951d95b13487 fileset: add function to switch revision where fileset will be evaluated
Yuya Nishihara <yuya@tcha.org>
parents: 31201
diff changeset
509 # filesets using matchctx.switch()
951d95b13487 fileset: add function to switch revision where fileset will be evaluated
Yuya Nishihara <yuya@tcha.org>
parents: 31201
diff changeset
510 _switchcallers = [
31203
4140d49d2efb fileset: add revs(revs, fileset) to evaluate set in working directory
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31202
diff changeset
511 'revs',
31205
6b098ac4542e fileset: add a 'status(...)' predicate to control evaluation context
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31204
diff changeset
512 'status',
31202
951d95b13487 fileset: add function to switch revision where fileset will be evaluated
Yuya Nishihara <yuya@tcha.org>
parents: 31201
diff changeset
513 ]
31198
ec5b56b50e19 fileset: add class to host special handling of initial subset
Yuya Nishihara <yuya@tcha.org>
parents: 29991
diff changeset
514
14678
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
515 def _intree(funcs, tree):
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
516 if isinstance(tree, tuple):
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
517 if tree[0] == 'func' and tree[1][0] == 'symbol':
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
518 if tree[1][1] in funcs:
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
519 return True
31202
951d95b13487 fileset: add function to switch revision where fileset will be evaluated
Yuya Nishihara <yuya@tcha.org>
parents: 31201
diff changeset
520 if tree[1][1] in _switchcallers:
951d95b13487 fileset: add function to switch revision where fileset will be evaluated
Yuya Nishihara <yuya@tcha.org>
parents: 31201
diff changeset
521 # arguments won't be evaluated in the current context
951d95b13487 fileset: add function to switch revision where fileset will be evaluated
Yuya Nishihara <yuya@tcha.org>
parents: 31201
diff changeset
522 return False
14678
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
523 for s in tree[1:]:
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
524 if _intree(funcs, s):
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
525 return True
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
526 return False
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
527
38613
760cc5dc01e8 fileset: restrict getfileset() to not return a computed set (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
528 def match(ctx, expr, badfn=None):
760cc5dc01e8 fileset: restrict getfileset() to not return a computed set (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
529 """Create a matcher for a single fileset expression"""
38845
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38844
diff changeset
530 tree = filesetlang.parse(expr)
38866
6371ab78c3b3 fileset: add phase to transform parsed tree
Yuya Nishihara <yuya@tcha.org>
parents: 38850
diff changeset
531 tree = filesetlang.analyze(tree)
38692
3700564c63fe fileset: remove fullmatchctx class
Yuya Nishihara <yuya@tcha.org>
parents: 38691
diff changeset
532 mctx = matchctx(ctx, _buildstatus(ctx, tree), badfn=badfn)
38689
ff5b6fca1082 fileset: rewrite predicates to return matcher not closed to subset (API) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38687
diff changeset
533 return getmatch(mctx, tree)
14678
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
534
31204
016c63d6658c fileset: allow to specify a basectx for status
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31203
diff changeset
535 def _buildstatus(ctx, tree, basectx=None):
14678
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
536 # do we need status info?
31204
016c63d6658c fileset: allow to specify a basectx for status
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31203
diff changeset
537
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
538 if _intree(_statuscallers, tree):
14678
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
539 unknown = _intree(['unknown'], tree)
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
540 ignored = _intree(['ignored'], tree)
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
541
31204
016c63d6658c fileset: allow to specify a basectx for status
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31203
diff changeset
542 if basectx is None:
016c63d6658c fileset: allow to specify a basectx for status
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31203
diff changeset
543 basectx = ctx.p1()
38813
af5c0c933af8 fileset: use ctx1.status(ctx2) instead of repo.status(ctx1, ctx2)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38758
diff changeset
544 return basectx.status(ctx, listunknown=unknown, listignored=ignored,
af5c0c933af8 fileset: use ctx1.status(ctx2) instead of repo.status(ctx1, ctx2)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38758
diff changeset
545 listclean=True)
14678
5ef7b87530f6 fileset: prescan parse tree to optimize status usage
Matt Mackall <mpm@selenic.com>
parents: 14677
diff changeset
546 else:
31201
3c3ab84e6e78 fileset: extract function that builds status tuple only if necessary
Yuya Nishihara <yuya@tcha.org>
parents: 31200
diff changeset
547 return None
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
548
28447
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
549 def loadpredicate(ui, extname, registrarobj):
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
550 """Load fileset predicates from specified registrarobj
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
551 """
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
552 for name, func in registrarobj._table.iteritems():
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
553 symbols[name] = func
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
554 if func._callstatus:
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
555 _statuscallers.add(name)
4eb5496c2bd4 registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28056
diff changeset
556
38690
5d9749c598f0 fileset: remove callexisting flag and mctx.existing() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38689
diff changeset
557 # load built-in predicates explicitly to setup _statuscallers
28448
7108834c76a2 fileset: replace predicate by filesetpredicate of registrar (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28447
diff changeset
558 loadpredicate(None, None, predicate)
7108834c76a2 fileset: replace predicate by filesetpredicate of registrar (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28447
diff changeset
559
14681
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
560 # tell hggettext to extract docstrings from these functions:
0744db5eb51c fileset: add some function help text
Matt Mackall <mpm@selenic.com>
parents: 14680
diff changeset
561 i18nfunctions = symbols.values()