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