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