Show More
@@ -1,67 +1,65 b'' | |||||
1 | //! The revset query language |
|
1 | //! The revset query language | |
2 | //! |
|
2 | //! | |
3 | //! <https://www.mercurial-scm.org/repo/hg/help/revsets> |
|
3 | //! <https://www.mercurial-scm.org/repo/hg/help/revsets> | |
4 |
|
4 | |||
5 | use crate::errors::HgError; |
|
5 | use crate::errors::HgError; | |
6 | use crate::repo::Repo; |
|
6 | use crate::repo::Repo; | |
7 | use crate::revlog::revlog::{Revlog, RevlogError}; |
|
7 | use crate::revlog::revlog::{Revlog, RevlogError}; | |
8 | use crate::revlog::NodePrefix; |
|
8 | use crate::revlog::NodePrefix; | |
9 | use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX}; |
|
9 | use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX}; | |
10 | use crate::Node; |
|
10 | use crate::Node; | |
11 |
|
11 | |||
12 | /// Resolve a query string into a single revision. |
|
12 | /// Resolve a query string into a single revision. | |
13 | /// |
|
13 | /// | |
14 | /// Only some of the revset language is implemented yet. |
|
14 | /// Only some of the revset language is implemented yet. | |
15 | pub fn resolve_single( |
|
15 | pub fn resolve_single( | |
16 | input: &str, |
|
16 | input: &str, | |
17 | repo: &Repo, |
|
17 | repo: &Repo, | |
18 | ) -> Result<Revision, RevlogError> { |
|
18 | ) -> Result<Revision, RevlogError> { | |
19 | let changelog = repo.changelog()?; |
|
19 | let changelog = repo.changelog()?; | |
20 |
|
20 | |||
21 | match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) { |
|
21 | match input { | |
22 | Err(RevlogError::InvalidRevision) => {} // Try other syntax |
|
22 | "null" => return Ok(NULL_REVISION), | |
23 | result => return result, |
|
23 | _ => {} | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | if input == "null" { |
|
26 | match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) { | |
27 | return Ok(NULL_REVISION); |
|
27 | Err(RevlogError::InvalidRevision) => { | |
|
28 | // TODO: support for the rest of the language here. | |||
|
29 | let msg = format!("cannot parse revset '{}'", input); | |||
|
30 | Err(HgError::unsupported(msg).into()) | |||
|
31 | } | |||
|
32 | result => return result, | |||
28 | } |
|
33 | } | |
29 |
|
||||
30 | // TODO: support for the rest of the language here. |
|
|||
31 |
|
||||
32 | Err( |
|
|||
33 | HgError::unsupported(format!("cannot parse revset '{}'", input)) |
|
|||
34 | .into(), |
|
|||
35 | ) |
|
|||
36 | } |
|
34 | } | |
37 |
|
35 | |||
38 | /// Resolve the small subset of the language suitable for revlogs other than |
|
36 | /// Resolve the small subset of the language suitable for revlogs other than | |
39 | /// the changelog, such as in `hg debugdata --manifest` CLI argument. |
|
37 | /// the changelog, such as in `hg debugdata --manifest` CLI argument. | |
40 | /// |
|
38 | /// | |
41 | /// * A non-negative decimal integer for a revision number, or |
|
39 | /// * A non-negative decimal integer for a revision number, or | |
42 | /// * An hexadecimal string, for the unique node ID that starts with this |
|
40 | /// * An hexadecimal string, for the unique node ID that starts with this | |
43 | /// prefix |
|
41 | /// prefix | |
44 | pub fn resolve_rev_number_or_hex_prefix( |
|
42 | pub fn resolve_rev_number_or_hex_prefix( | |
45 | input: &str, |
|
43 | input: &str, | |
46 | revlog: &Revlog, |
|
44 | revlog: &Revlog, | |
47 | ) -> Result<Revision, RevlogError> { |
|
45 | ) -> Result<Revision, RevlogError> { | |
48 | // The Python equivalent of this is part of `revsymbol` in |
|
46 | // The Python equivalent of this is part of `revsymbol` in | |
49 | // `mercurial/scmutil.py` |
|
47 | // `mercurial/scmutil.py` | |
50 |
|
48 | |||
51 | if let Ok(integer) = input.parse::<i32>() { |
|
49 | if let Ok(integer) = input.parse::<i32>() { | |
52 | if integer.to_string() == input |
|
50 | if integer.to_string() == input | |
53 | && integer >= 0 |
|
51 | && integer >= 0 | |
54 | && revlog.has_rev(integer) |
|
52 | && revlog.has_rev(integer) | |
55 | { |
|
53 | { | |
56 | return Ok(integer); |
|
54 | return Ok(integer); | |
57 | } |
|
55 | } | |
58 | } |
|
56 | } | |
59 | if let Ok(prefix) = NodePrefix::from_hex(input) { |
|
57 | if let Ok(prefix) = NodePrefix::from_hex(input) { | |
60 | if prefix.is_prefix_of(&Node::from_hex(WORKING_DIRECTORY_HEX).unwrap()) |
|
58 | if prefix.is_prefix_of(&Node::from_hex(WORKING_DIRECTORY_HEX).unwrap()) | |
61 | { |
|
59 | { | |
62 | return Err(RevlogError::WDirUnsupported); |
|
60 | return Err(RevlogError::WDirUnsupported); | |
63 | } |
|
61 | } | |
64 | return revlog.rev_from_node(prefix); |
|
62 | return revlog.rev_from_node(prefix); | |
65 | } |
|
63 | } | |
66 | Err(RevlogError::InvalidRevision) |
|
64 | Err(RevlogError::InvalidRevision) | |
67 | } |
|
65 | } |
General Comments 0
You need to be logged in to leave comments.
Login now