Commit Graph

84 Commits

Author SHA1 Message Date
Martin von Zweigbergk
c3406ac3db cleanup: use set literals
We no longer support Python 2.6, so we can now use set literals.
2017-02-10 16:56:29 -08:00
Jun Wu
6e4fd814fb fileset: use fctx.isbinary instead of util.binary(fctx.data())
filectx provides "isbinary" to test if the data is binary. Let's use it.

This enables other filectx implementations (like LFS) to override the
isbinary test.
2017-05-03 18:02:00 -07:00
Gregory Szorc
df777290b9 fileset: perform membership test against set for status queries
Previously, fileset functions operating on status items performed
membership tests against a list of items. When there are thousands
of items having a specific status, that test can be extremely
slow. Changing the membership test to a set makes this operation
substantially faster.

On the mozilla-central repo:

$ hg files -r d14cac631ecc 'set:added()'
before: 28.120s
after:   0.860s

$ hg status --change d14cac631ecc --added
0.690s
2017-03-28 14:40:13 -07:00
Yuya Nishihara
bdbe6facb9 fileset: drop false function signatures from revs() and status() docs
They should be inserted by @predicate helper.
2017-03-09 00:07:13 +09:00
Pierre-Yves David
a1ad299f67 fileset: add a 'status(...)' predicate to control evaluation context
Same as 'revs', this predicate does not select files but switches the evaluation
context. This allow to match file according arbitrary status call. We can now
express the same query as 'hg status'.

The API (two 'revsingle' class) have been picked instead of a single 'revs'
revset for multiple reasons:

 * it is less confusing to express
 * it allow to express more query (eg: backward status, cross branch status)
2017-03-03 14:08:20 +01:00
Pierre-Yves David
5b29e72b25 fileset: allow to specify a basectx for status
This will be used for a predicates that defines the status range of a match.
2017-03-03 14:08:06 +01:00
Pierre-Yves David
5be5f101f6 fileset: add revs(revs, fileset) to evaluate set in working directory
Unlike other functions, "revs()" does not select files but switches the
evaluation context. This allow to match file with property in another revision
that the one currently evaluated.

This changeset is based on work from Yuya Nishihara.
2017-03-03 12:44:56 +01:00
Yuya Nishihara
123bfcf3e9 fileset: add function to switch revision where fileset will be evaluated
If the subset isn't filtered yet, i.e. if fullmatchctx, the new subset is
recalculated from scratch. Otherwise, it is narrowed by the existing subset.
2015-01-24 19:41:56 +09:00
Yuya Nishihara
19f5256d23 fileset: extract function that builds status tuple only if necessary
This function will be used to recalculate status when mctx.ctx is switched.
2015-01-24 19:13:39 +09:00
Yuya Nishihara
69310d762a fileset: build initial subset in fullmatchctx class 2015-01-24 18:56:02 +09:00
Yuya Nishihara
081bed02eb fileset: extract function that builds initial subset from ctx or status
This function will be used to recalculate subset when mctx.ctx is switched.
2015-03-24 23:10:49 +09:00
Yuya Nishihara
b8e9d7ad88 fileset: add class to host special handling of initial subset
Future patches will add a function to switch mctx.ctx object so that we can
forcibly evaluate a fileset expression in a specified revision. For example,
new "revs()" function will be used to match predicate agains another revision

  $ hg revert 'set:revs(42, added())'

fullmatchctx class is similar to revset.fullreposet. It will allow us to
recalculate the subset only if it is not filtered yet.
2015-01-24 19:55:14 +09:00
timeless
1c84663088 help: clarify quotes are needed for filesets.size expressions 2016-09-21 16:33:37 +00:00
FUJIWARA Katsunori
13e7cbee4b fileset: replace predicate by filesetpredicate of registrar (API)
To make all built-in predicates be known to hggettext, loading
built-in predicates by loadpredicate() should be placed before fixing
i18nfunctions but after all of predicate decorating.
2016-03-11 04:14:54 +09:00
FUJIWARA Katsunori
f997d054b1 registrar: add filesetpredicate to mark a function as fileset predicate
filesetpredicate is used to replace fileset.predicate in subsequent
patch.

This patch also adds loadpredicate() to fileset, because this
combination helps to figure out how the name of "status caller" (or
"existing caller") predicate is put into _statuscallers (or
_existingcallers).

Listing up loadpredicate() in dispatch.extraloaders causes implicit
loading fileset predicate functions at loading (3rd party) extension.
2016-03-11 04:14:54 +09:00
Matt Harbison
0fa9e4d8ca fileset: fix copy/paste in eol() error message 2016-02-18 22:32:18 -05:00
timeless
998fd9af34 fileset: add hint for list error to use or 2015-12-23 17:54:13 +00:00
FUJIWARA Katsunori
2cb14bf8f0 fileset: detect unintentional existing() invocation at runtime
A fileset predicate can invoke 'matchctx.existing()' successfully,
even if it isn't marked as "existing caller". It is aborted only in
some corner cases: e.g. there were one deleted file in the working
directory (see 2c5c0790cbcc for detail).

This patch makes 'matchctx.existing()' invocation abort if not
'_existingenabled', which is true only while "existing caller"
running.

After this changes, non-"existing caller" predicate function is
aborted immediately, whenever it invokes 'matchctx.existing()'. This
prevent developer from forgetting to mark a predicate as "existing
caller".

BTW, unintentional 'matchctx.status()' invocation can be detected
easily without any additional trick like this patch, because it
returns 'None' if a predicate isn't marked as "status caller", and
referring field (e.g. '.modified') of it is always aborted.
2015-12-21 22:31:16 +09:00
FUJIWARA Katsunori
cde1d3d500 fileset: use set instead of list to mark predicates for efficiency (API)
This reduces cost of examining whether given predicate calls
'matchctx.status()' or 'matchctx.existing()' in 'getfileset()' at
runtime.

This kind of examination is used also in subsequent patch, which
detects unintentional 'matchctx.existing()' invocation per each
predicate evaluation.
2015-12-21 22:31:16 +09:00
FUJIWARA Katsunori
90eaf4bbec fileset: use decorator to mark a predicate as "existing caller"
This can localize changes for adding (or removing) an "existing
caller" predicate function in source code.
2015-12-21 22:31:16 +09:00
FUJIWARA Katsunori
c965a4dbaa fileset: use decorator to mark a predicate as "status caller"
Before this patch, predicates calling 'matchctx.status()' are listed
up by immediate list value in 'getfileset()'.

This prevents 3rd party extensions from adding specific predicate
calling 'matchctx.status()'.

This uses decorator to mark a predicate as "status caller".

This can also localize changes for adding (or removing) a "status
caller" predicate function in source code.
2015-12-21 22:31:16 +09:00
FUJIWARA Katsunori
a8588195a6 fileset: use decorator to mark a function as fileset predicate
Using decorator can localize changes for adding (or removing) a
fileset predicate function in source code.

It is also useful to pick predicates up for specific purpose. For
example, subsequent patches marks predicates as "call status" or "use
existing" via decorator.

To avoid (1) redundancy between "predicate name" and (the beginning
of) help document, and (2) accidental typo of help document, this
patch also makes decorator put predicate declration into the beginning
of help.
2015-12-21 22:31:16 +09:00
FUJIWARA Katsunori
655c371178 fileset: treat encoding and eol as the predicate calling _existing
Before this patch, predicate function 'encoding' and 'eol' aren't
listed up in '_existingcallers', even though they invoke 'existing()'.

This causes unexpected failure of these predicate, if there is a
(manually) deleted file in the working directory.

2c5c0790cbcc and 12b403664548 seem to overlook putting already
existing 'encoding' or newly introduced 'eol' into '_existingcallers'.

This patch also changes order of fileset "eol(unix)" output in test,
because "existing caller" predicates show "A(dded)" files before
"C(lean)" ones.
2015-12-21 22:31:16 +09:00
liscju
616740cead fileset: add missing() predicate (issue4925)
Help of status cmd defines status file of 'missing', what is
called in fileset 'deleted'. To stay consistent this patch
introduces missing() predicate which in fact is alias to
'deleted'.
2015-11-18 20:55:32 +01:00
Siddharth Agarwal
178aa21f0d fileset: switch to mergestate.read()
See previous patches for why we're doing this.
2015-11-17 13:57:38 -08:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Yuya Nishihara
375ffa2a98 fileset: handle error of string unescaping 2015-09-10 23:32:36 +09:00
timeless@mozdev.org
9489eda0f2 help: filesets show hg resolve command 2015-09-08 11:35:22 -04:00
timeless@mozdev.org
7134fe8574 help: filesets show hg status command 2015-09-08 11:30:01 -04:00
Matt Mackall
6c04738a65 merge with stable 2015-08-10 15:30:28 -05:00
Gregory Szorc
bf31c39d5d fileset: use absolute_import 2015-08-08 18:34:37 -07:00
Anton Shestakov
6a4a921104 filesets: ignore unit case in size() predicate for single value
When specifying one plain value in size(), e.g. size(1k), fileset tries to
guess the upper bound automatically (see the comment in _sizetomax()). It
didn't ignore the specified unit's case, and so size("1 GB"), for example,
produced this error:

hg: parse error: couldn't parse size: 1 GB

Let's do the same thing that util.sizetoint() does: .lower().

The two test lines without output just check that there are no parse errors.
2015-08-08 14:42:27 +08:00
Yuya Nishihara
b4caf94446 parser: separate actions for primary expression and prefix operator
This will allow us to define both a primary expression, ":", and a prefix
operator, ":y". The ambiguity will be resolved by the next patch.

Prefix actions in elements table are adjusted as follows:

  original prefix      primary  prefix
  -----------------    -------- -----------------
  ("group", 1, ")") -> n/a      ("group", 1, ")")
  ("negate", 19)    -> n/a      ("negate", 19)
  ("symbol",)       -> "symbol" n/a
2015-07-05 12:02:13 +09:00
Yuya Nishihara
4645c24be5 parser: fill invalid infix and suffix actions by None
This can simplify the expansion of (prefix, infix, suffix) actions.
2015-07-05 11:17:22 +09:00
Yuya Nishihara
b677e35b5b parser: add comment about structure of elements to each table 2015-07-05 11:06:58 +09:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Yuya Nishihara
fe462ed8ac parser: accept iterator of tokens instead of tokenizer function and program
This can simplify the interface of parse() function. Our tokenizer tends to
have optional arguments other than the message to be parsed.

Before this patch, the "lookup" argument existed only for the revset, and the
templater had to pack [program, start, end] to be passed to its tokenizer.
2015-06-21 00:49:26 +09:00
Matt Harbison
1306998af7 fileset: don't suggest private or undocumented queries
Unlike revsets, it looks like all of the filesets are documented, so there's
really nothing to test.  This is aimed more at parity with revsets and
future-proofing.
2015-06-20 11:07:36 -04:00
Yuya Nishihara
dfdaf0679a fileset: pretty print syntax tree in debug output 2015-04-26 22:26:44 +09:00
Yuya Nishihara
c52c748a86 fileset: move validation of incomplete parsing to parse() function
fileset.parse() should be responsible for all parsing errors as well.
2015-04-26 19:50:42 +09:00
Siddharth Agarwal
63850f5fd4 fileset: add a fileset for portable filenames
This has mostly the same semantics as the files that the 'ui.portablefilenames'
config option would warn or abort about. The only difference is filenames that
case-fold to the same string -- given a set of filenames we've already
checked we can check whether a new one collides with them, but we don't have a
way to tell which filename it collided with.
2015-03-19 21:26:18 -07:00
Matt Harbison
72de876f6c fileset: replace 'ctx._repo' with 'ctx.repo()' 2015-03-12 23:02:19 -04:00
Augie Fackler
18d6bf235a fileset: use UnknownIdentifier where appropriate 2015-01-26 14:31:48 -05:00
FUJIWARA Katsunori
13d9d50897 i18n: add i18n comment to error messages of filesets predicates 2014-11-01 02:43:08 +09:00
Martin von Zweigbergk
05e97c1d55 fileset: access status fields by name rather than index 2014-10-04 21:58:01 -07:00
Augie Fackler
acff2f02d0 merge with stable 2014-01-01 18:28:40 -05:00
Yuya Nishihara
cb7a1dd14c fileset, revset: do not use global parser object for thread safety
parse() cannot be called at the same time because a parser object keeps its
states.  This is no problem for command-line hg client, but it would cause
strange errors in multi-threaded hgweb.

Creating parser object is not too expensive.

original:
% python -m timeit -s 'from mercurial import revset' 'revset.parse("0::tip")'
100000 loops, best of 3: 11.3 usec per loop

thread-safe:
% python -m timeit -s 'from mercurial import revset' 'revset.parse("0::tip")'
100000 loops, best of 3: 13.1 usec per loop
2013-12-21 12:44:19 +09:00
Augie Fackler
9f876f6c89 cleanup: move stdlib imports to their own import statement
There are a few warnings still produced by my import checker, but
those are false positives produced by modules that share a name with
stdlib modules.
2013-11-06 16:48:06 -05:00
Matt Mackall
704604439e fileset: handle underbar in symbols
This was documented, but not implemented.
2013-07-23 14:18:56 -05:00
Bryan O'Sullivan
502e5bc1d1 util: migrate fileset._sizetoint to util.sizetoint
The size counting code introduced in 233431858f4c duplicated existing
(but unknown-to-me) code in fileset, so prepare to eliminate the
duplication.
2013-05-14 15:16:43 -07:00