Mercurial > public > mercurial-scm > hg
annotate rust/hg-core/src/revset.rs @ 48061:060cd909439f
dirstate: drop all logic around the "non-normal" sets
The dirstate has a lot of code to compute a set of all "non-normal" and
"from_other_parent" entries.
This is all used in one, unique, location, when `setparent` is called and moved
from a merge to a non merge. At that time, any "merge related" information has
to be dropped. This is mostly useful for command like `graft` or `shelve` that
move to a single-parent state -before- the commit. Otherwise the commit will
already have removed all traces of the merge information in the dirstate (e.g.
for a regular merges).
The bookkeeping for these sets is quite invasive. And it seems simpler to just
drop it and do the full computation in the single location where we actually
use it (since we have to do the computation at least once anyway).
This simplify the code a lot, and clarify why this kind of computation is
needed.
The possible drawback compared to the previous code are:
- if the operation happens in a loop, we will end up doing it multiple time,
- the C code to detect entry of interest have been dropped, for now. It will be
re-introduced later, with a processing code directly in C for even faster
operation.
Differential Revision: https://phab.mercurial-scm.org/D11507
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 28 Sep 2021 20:05:37 +0200 |
parents | 6f579618ea7b |
children | ddde80830aea |
rev | line source |
---|---|
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
1 //! The revset query language |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
2 //! |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
3 //! <https://www.mercurial-scm.org/repo/hg/help/revsets> |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
4 |
46725
df247f58ecee
rhg: Fall back to Python for unsupported revset syntax
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
5 use crate::errors::HgError; |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
6 use crate::repo::Repo; |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
7 use crate::revlog::revlog::{Revlog, RevlogError}; |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
8 use crate::revlog::NodePrefix; |
46821
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46725
diff
changeset
|
9 use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX}; |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46725
diff
changeset
|
10 use crate::Node; |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
11 |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
12 /// Resolve a query string into a single revision. |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
13 /// |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
14 /// Only some of the revset language is implemented yet. |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
15 pub fn resolve_single( |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
16 input: &str, |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
17 repo: &Repo, |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
18 ) -> Result<Revision, RevlogError> { |
47959
21d25e9ee58e
rust: Keep lazily-initialized Changelog and Manifest log on the Repo object
Simon Sapin <simon.sapin@octobus.net>
parents:
46821
diff
changeset
|
19 let changelog = repo.changelog()?; |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
20 |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
21 match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) { |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
22 Err(RevlogError::InvalidRevision) => {} // Try other syntax |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
23 result => return result, |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
24 } |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
25 |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
26 if input == "null" { |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
27 return Ok(NULL_REVISION); |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
28 } |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
29 |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
30 // TODO: support for the rest of the language here. |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
31 |
46725
df247f58ecee
rhg: Fall back to Python for unsupported revset syntax
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
32 Err( |
df247f58ecee
rhg: Fall back to Python for unsupported revset syntax
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
33 HgError::unsupported(format!("cannot parse revset '{}'", input)) |
df247f58ecee
rhg: Fall back to Python for unsupported revset syntax
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
34 .into(), |
df247f58ecee
rhg: Fall back to Python for unsupported revset syntax
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
35 ) |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
36 } |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
37 |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
38 /// Resolve the small subset of the language suitable for revlogs other than |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
39 /// the changelog, such as in `hg debugdata --manifest` CLI argument. |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
40 /// |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
41 /// * A non-negative decimal integer for a revision number, or |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
42 /// * An hexadecimal string, for the unique node ID that starts with this |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
43 /// prefix |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
44 pub fn resolve_rev_number_or_hex_prefix( |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
45 input: &str, |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
46 revlog: &Revlog, |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
47 ) -> Result<Revision, RevlogError> { |
47962
8c29af0f6d6e
rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents:
47959
diff
changeset
|
48 // The Python equivalent of this is part of `revsymbol` in |
8c29af0f6d6e
rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents:
47959
diff
changeset
|
49 // `mercurial/scmutil.py` |
8c29af0f6d6e
rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents:
47959
diff
changeset
|
50 |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
51 if let Ok(integer) = input.parse::<i32>() { |
47962
8c29af0f6d6e
rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents:
47959
diff
changeset
|
52 if integer.to_string() == input |
8c29af0f6d6e
rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents:
47959
diff
changeset
|
53 && integer >= 0 |
8c29af0f6d6e
rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents:
47959
diff
changeset
|
54 && revlog.has_rev(integer) |
8c29af0f6d6e
rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents:
47959
diff
changeset
|
55 { |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
56 return Ok(integer); |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
57 } |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
58 } |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
59 if let Ok(prefix) = NodePrefix::from_hex(input) { |
46821
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46725
diff
changeset
|
60 if prefix.is_prefix_of(&Node::from_hex(WORKING_DIRECTORY_HEX).unwrap()) |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46725
diff
changeset
|
61 { |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46725
diff
changeset
|
62 return Err(RevlogError::WDirUnsupported); |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46725
diff
changeset
|
63 } |
47968
6f579618ea7b
rust: Rename the `Revlog::get_node_rev` method to `rev_from_node`
Simon Sapin <simon.sapin@octobus.net>
parents:
47962
diff
changeset
|
64 return revlog.rev_from_node(prefix); |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
65 } |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
66 Err(RevlogError::InvalidRevision) |
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
67 } |