annotate rust/hg-core/src/revset.rs @ 52552:66e34bc44280

rhg: set the expected temp file permissions (0o666 minus umask) This continues the theme of a48c688d3e80, and fixes the bug #6375, which was causing some problems for us, where a non-group-readable file can't be copied, which breaks some tools that copy the repo. This affects both the `checkexec` file and the temporary file we use for filesystem time measurement, since either of these files remaining on disk can cause this problem, and the 0666 permissions are just the better default here.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 05 Dec 2024 13:17:32 +0000
parents 652149ed64f0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46501
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
46738
df247f58ecee rhg: Fall back to Python for unsupported revset syntax
Simon Sapin <simon.sapin@octobus.net>
parents: 46501
diff changeset
5 use crate::errors::HgError;
46501
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::NodePrefix;
46821
e8ae91b1a63d rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46738
diff changeset
8 use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX};
50010
750409505286 rust-clippy: merge "revlog" module definition and struct implementation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50003
diff changeset
9 use crate::revlog::{Revlog, RevlogError};
46821
e8ae91b1a63d rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46738
diff changeset
10 use crate::Node;
46501
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> {
47987
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()?;
46501
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
20
48092
ddde80830aea rust-revset: add separate match logic for shortcuts
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47996
diff changeset
21 match input {
48093
3da7bf75fdb2 rust-revset: support explicit `.` revision
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48092
diff changeset
22 "." => {
3da7bf75fdb2 rust-revset: support explicit `.` revision
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48092
diff changeset
23 let p1 = repo.dirstate_parents()?.p1;
50003
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48093
diff changeset
24 return changelog.revlog.rev_from_node(p1.into());
48093
3da7bf75fdb2 rust-revset: support explicit `.` revision
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48092
diff changeset
25 }
48092
ddde80830aea rust-revset: add separate match logic for shortcuts
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47996
diff changeset
26 "null" => return Ok(NULL_REVISION),
ddde80830aea rust-revset: add separate match logic for shortcuts
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47996
diff changeset
27 _ => {}
46501
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
48092
ddde80830aea rust-revset: add separate match logic for shortcuts
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47996
diff changeset
30 match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) {
52069
652149ed64f0 rust: improve `InvalidRevision` error message
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50990
diff changeset
31 Err(RevlogError::InvalidRevision(revision)) => {
48092
ddde80830aea rust-revset: add separate match logic for shortcuts
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47996
diff changeset
32 // TODO: support for the rest of the language here.
52069
652149ed64f0 rust: improve `InvalidRevision` error message
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50990
diff changeset
33 let msg = format!("cannot parse revset '{}'", revision);
48092
ddde80830aea rust-revset: add separate match logic for shortcuts
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47996
diff changeset
34 Err(HgError::unsupported(msg).into())
ddde80830aea rust-revset: add separate match logic for shortcuts
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47996
diff changeset
35 }
50003
e98fd81bb151 rust-clippy: fix most warnings in `hg-core`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 48093
diff changeset
36 result => result,
46501
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 }
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
39
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
40 /// 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
41 /// 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
42 ///
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
43 /// * 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
44 /// * 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
45 /// prefix
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
46 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
47 input: &str,
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
48 revlog: &Revlog,
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
49 ) -> Result<Revision, RevlogError> {
47990
8c29af0f6d6e rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents: 47987
diff changeset
50 // 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: 47987
diff changeset
51 // `mercurial/scmutil.py`
8c29af0f6d6e rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents: 47987
diff changeset
52
46501
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
53 if let Ok(integer) = input.parse::<i32>() {
47990
8c29af0f6d6e rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents: 47987
diff changeset
54 if integer.to_string() == input
8c29af0f6d6e rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents: 47987
diff changeset
55 && integer >= 0
50988
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50010
diff changeset
56 && revlog.has_rev(integer.into())
47990
8c29af0f6d6e rhg: Align with Python on some revset parsing corner cases
Simon Sapin <simon.sapin@octobus.net>
parents: 47987
diff changeset
57 {
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
58 // This is fine because we've just checked that the revision is
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
59 // valid for the given revlog.
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
60 return Ok(Revision(integer));
46501
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
61 }
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
62 }
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
63 if let Ok(prefix) = NodePrefix::from_hex(input) {
46821
e8ae91b1a63d rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46738
diff changeset
64 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: 46738
diff changeset
65 {
e8ae91b1a63d rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46738
diff changeset
66 return Err(RevlogError::WDirUnsupported);
e8ae91b1a63d rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46738
diff changeset
67 }
47996
6f579618ea7b rust: Rename the `Revlog::get_node_rev` method to `rev_from_node`
Simon Sapin <simon.sapin@octobus.net>
parents: 47990
diff changeset
68 return revlog.rev_from_node(prefix);
46501
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
69 }
52069
652149ed64f0 rust: improve `InvalidRevision` error message
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50990
diff changeset
70 Err(RevlogError::InvalidRevision(input.to_string()))
46501
4b381dbbf8b7 rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
71 }