changeset 38870 | bfd5def3fe02 |
parent 38869 | 7e7e2b2ff284 |
child 38902 | 61ab546b71c3 |
38869:7e7e2b2ff284 | 38870:bfd5def3fe02 |
---|---|
86 # filesets using matchctx.status() |
86 # filesets using matchctx.status() |
87 _statuscallers = set() |
87 _statuscallers = set() |
88 |
88 |
89 predicate = registrar.filesetpredicate() |
89 predicate = registrar.filesetpredicate() |
90 |
90 |
91 @predicate('modified()', callstatus=True) |
91 @predicate('modified()', callstatus=True, weight=10) |
92 def modified(mctx, x): |
92 def modified(mctx, x): |
93 """File that is modified according to :hg:`status`. |
93 """File that is modified according to :hg:`status`. |
94 """ |
94 """ |
95 # i18n: "modified" is a keyword |
95 # i18n: "modified" is a keyword |
96 getargs(x, 0, 0, _("modified takes no arguments")) |
96 getargs(x, 0, 0, _("modified takes no arguments")) |
97 s = set(mctx.status().modified) |
97 s = set(mctx.status().modified) |
98 return mctx.predicate(s.__contains__, predrepr='modified') |
98 return mctx.predicate(s.__contains__, predrepr='modified') |
99 |
99 |
100 @predicate('added()', callstatus=True) |
100 @predicate('added()', callstatus=True, weight=10) |
101 def added(mctx, x): |
101 def added(mctx, x): |
102 """File that is added according to :hg:`status`. |
102 """File that is added according to :hg:`status`. |
103 """ |
103 """ |
104 # i18n: "added" is a keyword |
104 # i18n: "added" is a keyword |
105 getargs(x, 0, 0, _("added takes no arguments")) |
105 getargs(x, 0, 0, _("added takes no arguments")) |
106 s = set(mctx.status().added) |
106 s = set(mctx.status().added) |
107 return mctx.predicate(s.__contains__, predrepr='added') |
107 return mctx.predicate(s.__contains__, predrepr='added') |
108 |
108 |
109 @predicate('removed()', callstatus=True) |
109 @predicate('removed()', callstatus=True, weight=10) |
110 def removed(mctx, x): |
110 def removed(mctx, x): |
111 """File that is removed according to :hg:`status`. |
111 """File that is removed according to :hg:`status`. |
112 """ |
112 """ |
113 # i18n: "removed" is a keyword |
113 # i18n: "removed" is a keyword |
114 getargs(x, 0, 0, _("removed takes no arguments")) |
114 getargs(x, 0, 0, _("removed takes no arguments")) |
115 s = set(mctx.status().removed) |
115 s = set(mctx.status().removed) |
116 return mctx.predicate(s.__contains__, predrepr='removed') |
116 return mctx.predicate(s.__contains__, predrepr='removed') |
117 |
117 |
118 @predicate('deleted()', callstatus=True) |
118 @predicate('deleted()', callstatus=True, weight=10) |
119 def deleted(mctx, x): |
119 def deleted(mctx, x): |
120 """Alias for ``missing()``. |
120 """Alias for ``missing()``. |
121 """ |
121 """ |
122 # i18n: "deleted" is a keyword |
122 # i18n: "deleted" is a keyword |
123 getargs(x, 0, 0, _("deleted takes no arguments")) |
123 getargs(x, 0, 0, _("deleted takes no arguments")) |
124 s = set(mctx.status().deleted) |
124 s = set(mctx.status().deleted) |
125 return mctx.predicate(s.__contains__, predrepr='deleted') |
125 return mctx.predicate(s.__contains__, predrepr='deleted') |
126 |
126 |
127 @predicate('missing()', callstatus=True) |
127 @predicate('missing()', callstatus=True, weight=10) |
128 def missing(mctx, x): |
128 def missing(mctx, x): |
129 """File that is missing according to :hg:`status`. |
129 """File that is missing according to :hg:`status`. |
130 """ |
130 """ |
131 # i18n: "missing" is a keyword |
131 # i18n: "missing" is a keyword |
132 getargs(x, 0, 0, _("missing takes no arguments")) |
132 getargs(x, 0, 0, _("missing takes no arguments")) |
133 s = set(mctx.status().deleted) |
133 s = set(mctx.status().deleted) |
134 return mctx.predicate(s.__contains__, predrepr='deleted') |
134 return mctx.predicate(s.__contains__, predrepr='deleted') |
135 |
135 |
136 @predicate('unknown()', callstatus=True) |
136 @predicate('unknown()', callstatus=True, weight=50) |
137 def unknown(mctx, x): |
137 def unknown(mctx, x): |
138 """File that is unknown according to :hg:`status`.""" |
138 """File that is unknown according to :hg:`status`.""" |
139 # i18n: "unknown" is a keyword |
139 # i18n: "unknown" is a keyword |
140 getargs(x, 0, 0, _("unknown takes no arguments")) |
140 getargs(x, 0, 0, _("unknown takes no arguments")) |
141 s = set(mctx.status().unknown) |
141 s = set(mctx.status().unknown) |
142 return mctx.predicate(s.__contains__, predrepr='unknown') |
142 return mctx.predicate(s.__contains__, predrepr='unknown') |
143 |
143 |
144 @predicate('ignored()', callstatus=True) |
144 @predicate('ignored()', callstatus=True, weight=50) |
145 def ignored(mctx, x): |
145 def ignored(mctx, x): |
146 """File that is ignored according to :hg:`status`.""" |
146 """File that is ignored according to :hg:`status`.""" |
147 # i18n: "ignored" is a keyword |
147 # i18n: "ignored" is a keyword |
148 getargs(x, 0, 0, _("ignored takes no arguments")) |
148 getargs(x, 0, 0, _("ignored takes no arguments")) |
149 s = set(mctx.status().ignored) |
149 s = set(mctx.status().ignored) |
150 return mctx.predicate(s.__contains__, predrepr='ignored') |
150 return mctx.predicate(s.__contains__, predrepr='ignored') |
151 |
151 |
152 @predicate('clean()', callstatus=True) |
152 @predicate('clean()', callstatus=True, weight=10) |
153 def clean(mctx, x): |
153 def clean(mctx, x): |
154 """File that is clean according to :hg:`status`. |
154 """File that is clean according to :hg:`status`. |
155 """ |
155 """ |
156 # i18n: "clean" is a keyword |
156 # i18n: "clean" is a keyword |
157 getargs(x, 0, 0, _("clean takes no arguments")) |
157 getargs(x, 0, 0, _("clean takes no arguments")) |
163 """File that is under Mercurial control.""" |
163 """File that is under Mercurial control.""" |
164 # i18n: "tracked" is a keyword |
164 # i18n: "tracked" is a keyword |
165 getargs(x, 0, 0, _("tracked takes no arguments")) |
165 getargs(x, 0, 0, _("tracked takes no arguments")) |
166 return mctx.predicate(mctx.ctx.__contains__, predrepr='tracked') |
166 return mctx.predicate(mctx.ctx.__contains__, predrepr='tracked') |
167 |
167 |
168 @predicate('binary()') |
168 @predicate('binary()', weight=30) |
169 def binary(mctx, x): |
169 def binary(mctx, x): |
170 """File that appears to be binary (contains NUL bytes). |
170 """File that appears to be binary (contains NUL bytes). |
171 """ |
171 """ |
172 # i18n: "binary" is a keyword |
172 # i18n: "binary" is a keyword |
173 getargs(x, 0, 0, _("binary takes no arguments")) |
173 getargs(x, 0, 0, _("binary takes no arguments")) |
190 # i18n: "symlink" is a keyword |
190 # i18n: "symlink" is a keyword |
191 getargs(x, 0, 0, _("symlink takes no arguments")) |
191 getargs(x, 0, 0, _("symlink takes no arguments")) |
192 ctx = mctx.ctx |
192 ctx = mctx.ctx |
193 return mctx.predicate(lambda f: ctx.flags(f) == 'l', predrepr='symlink') |
193 return mctx.predicate(lambda f: ctx.flags(f) == 'l', predrepr='symlink') |
194 |
194 |
195 @predicate('resolved()') |
195 @predicate('resolved()', weight=10) |
196 def resolved(mctx, x): |
196 def resolved(mctx, x): |
197 """File that is marked resolved according to :hg:`resolve -l`. |
197 """File that is marked resolved according to :hg:`resolve -l`. |
198 """ |
198 """ |
199 # i18n: "resolved" is a keyword |
199 # i18n: "resolved" is a keyword |
200 getargs(x, 0, 0, _("resolved takes no arguments")) |
200 getargs(x, 0, 0, _("resolved takes no arguments")) |
202 return mctx.never() |
202 return mctx.never() |
203 ms = merge.mergestate.read(mctx.ctx.repo()) |
203 ms = merge.mergestate.read(mctx.ctx.repo()) |
204 return mctx.predicate(lambda f: f in ms and ms[f] == 'r', |
204 return mctx.predicate(lambda f: f in ms and ms[f] == 'r', |
205 predrepr='resolved') |
205 predrepr='resolved') |
206 |
206 |
207 @predicate('unresolved()') |
207 @predicate('unresolved()', weight=10) |
208 def unresolved(mctx, x): |
208 def unresolved(mctx, x): |
209 """File that is marked unresolved according to :hg:`resolve -l`. |
209 """File that is marked unresolved according to :hg:`resolve -l`. |
210 """ |
210 """ |
211 # i18n: "unresolved" is a keyword |
211 # i18n: "unresolved" is a keyword |
212 getargs(x, 0, 0, _("unresolved takes no arguments")) |
212 getargs(x, 0, 0, _("unresolved takes no arguments")) |
214 return mctx.never() |
214 return mctx.never() |
215 ms = merge.mergestate.read(mctx.ctx.repo()) |
215 ms = merge.mergestate.read(mctx.ctx.repo()) |
216 return mctx.predicate(lambda f: f in ms and ms[f] == 'u', |
216 return mctx.predicate(lambda f: f in ms and ms[f] == 'u', |
217 predrepr='unresolved') |
217 predrepr='unresolved') |
218 |
218 |
219 @predicate('hgignore()') |
219 @predicate('hgignore()', weight=10) |
220 def hgignore(mctx, x): |
220 def hgignore(mctx, x): |
221 """File that matches the active .hgignore pattern. |
221 """File that matches the active .hgignore pattern. |
222 """ |
222 """ |
223 # i18n: "hgignore" is a keyword |
223 # i18n: "hgignore" is a keyword |
224 getargs(x, 0, 0, _("hgignore takes no arguments")) |
224 getargs(x, 0, 0, _("hgignore takes no arguments")) |
225 return mctx.ctx.repo().dirstate._ignore |
225 return mctx.ctx.repo().dirstate._ignore |
226 |
226 |
227 @predicate('portable()') |
227 @predicate('portable()', weight=0.5) |
228 def portable(mctx, x): |
228 def portable(mctx, x): |
229 """File that has a portable name. (This doesn't include filenames with case |
229 """File that has a portable name. (This doesn't include filenames with case |
230 collisions.) |
230 collisions.) |
231 """ |
231 """ |
232 # i18n: "portable" is a keyword |
232 # i18n: "portable" is a keyword |
233 getargs(x, 0, 0, _("portable takes no arguments")) |
233 getargs(x, 0, 0, _("portable takes no arguments")) |
234 return mctx.predicate(lambda f: util.checkwinfilename(f) is None, |
234 return mctx.predicate(lambda f: util.checkwinfilename(f) is None, |
235 predrepr='portable') |
235 predrepr='portable') |
236 |
236 |
237 @predicate('grep(regex)') |
237 @predicate('grep(regex)', weight=30) |
238 def grep(mctx, x): |
238 def grep(mctx, x): |
239 """File contains the given regular expression. |
239 """File contains the given regular expression. |
240 """ |
240 """ |
241 try: |
241 try: |
242 # i18n: "grep" is a keyword |
242 # i18n: "grep" is a keyword |
286 else: |
286 else: |
287 a = util.sizetoint(expr) |
287 a = util.sizetoint(expr) |
288 b = _sizetomax(expr) |
288 b = _sizetomax(expr) |
289 return lambda x: x >= a and x <= b |
289 return lambda x: x >= a and x <= b |
290 |
290 |
291 @predicate('size(expression)') |
291 @predicate('size(expression)', weight=10) |
292 def size(mctx, x): |
292 def size(mctx, x): |
293 """File size matches the given expression. Examples: |
293 """File size matches the given expression. Examples: |
294 |
294 |
295 - size('1k') - files from 1024 to 2047 bytes |
295 - size('1k') - files from 1024 to 2047 bytes |
296 - size('< 20k') - files less than 20480 bytes |
296 - size('< 20k') - files less than 20480 bytes |
301 expr = getstring(x, _("size requires an expression")) |
301 expr = getstring(x, _("size requires an expression")) |
302 m = sizematcher(expr) |
302 m = sizematcher(expr) |
303 return mctx.fpredicate(lambda fctx: m(fctx.size()), |
303 return mctx.fpredicate(lambda fctx: m(fctx.size()), |
304 predrepr=('size(%r)', expr), cache=True) |
304 predrepr=('size(%r)', expr), cache=True) |
305 |
305 |
306 @predicate('encoding(name)') |
306 @predicate('encoding(name)', weight=30) |
307 def encoding(mctx, x): |
307 def encoding(mctx, x): |
308 """File can be successfully decoded with the given character |
308 """File can be successfully decoded with the given character |
309 encoding. May not be useful for encodings other than ASCII and |
309 encoding. May not be useful for encodings other than ASCII and |
310 UTF-8. |
310 UTF-8. |
311 """ |
311 """ |
323 except UnicodeDecodeError: |
323 except UnicodeDecodeError: |
324 return False |
324 return False |
325 |
325 |
326 return mctx.fpredicate(encp, predrepr=('encoding(%r)', enc), cache=True) |
326 return mctx.fpredicate(encp, predrepr=('encoding(%r)', enc), cache=True) |
327 |
327 |
328 @predicate('eol(style)') |
328 @predicate('eol(style)', weight=30) |
329 def eol(mctx, x): |
329 def eol(mctx, x): |
330 """File contains newlines of the given style (dos, unix, mac). Binary |
330 """File contains newlines of the given style (dos, unix, mac). Binary |
331 files are excluded, files with mixed line endings match multiple |
331 files are excluded, files with mixed line endings match multiple |
332 styles. |
332 styles. |
333 """ |
333 """ |
357 def copiedp(fctx): |
357 def copiedp(fctx): |
358 p = fctx.parents() |
358 p = fctx.parents() |
359 return p and p[0].path() != fctx.path() |
359 return p and p[0].path() != fctx.path() |
360 return mctx.fpredicate(copiedp, predrepr='copied', cache=True) |
360 return mctx.fpredicate(copiedp, predrepr='copied', cache=True) |
361 |
361 |
362 @predicate('revs(revs, pattern)') |
362 @predicate('revs(revs, pattern)', weight=10) |
363 def revs(mctx, x): |
363 def revs(mctx, x): |
364 """Evaluate set in the specified revisions. If the revset match multiple |
364 """Evaluate set in the specified revisions. If the revset match multiple |
365 revs, this will return file matching pattern in any of the revision. |
365 revs, this will return file matching pattern in any of the revision. |
366 """ |
366 """ |
367 # i18n: "revs" is a keyword |
367 # i18n: "revs" is a keyword |
379 return mctx.never() |
379 return mctx.never() |
380 if len(matchers) == 1: |
380 if len(matchers) == 1: |
381 return matchers[0] |
381 return matchers[0] |
382 return matchmod.unionmatcher(matchers) |
382 return matchmod.unionmatcher(matchers) |
383 |
383 |
384 @predicate('status(base, rev, pattern)') |
384 @predicate('status(base, rev, pattern)', weight=10) |
385 def status(mctx, x): |
385 def status(mctx, x): |
386 """Evaluate predicate using status change between ``base`` and |
386 """Evaluate predicate using status change between ``base`` and |
387 ``rev``. Examples: |
387 ``rev``. Examples: |
388 |
388 |
389 - ``status(3, 7, added())`` - matches files added from "3" to "7" |
389 - ``status(3, 7, added())`` - matches files added from "3" to "7" |