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