##// END OF EJS Templates
rhg: read [paths] for `--repository` value...
rhg: read [paths] for `--repository` value hg parses `-R` and `--repository` CLI arguments "early" in order to know which local repository to load config from. (Config can then affect whether or how to fall back.) The value of of those arguments can be not only a filesystem path, but also an alias configured in the `[paths]` section. This part was missing in rhg and this patch implements that. The current patch still lacks functionality to read config of current repository if we are not at root of repo. That will be fixed in upcoming patches. A new crate `home` is added to get path of home directory. Differential Revision: https://phab.mercurial-scm.org/D10296

File last commit:

r47577:e8ae91b1 default
r48196:ebdef628 default
Show More
revset.rs
62 lines | 1.8 KiB | application/rls-services+xml | RustLexer
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 //! The revset query language
//!
//! <https://www.mercurial-scm.org/repo/hg/help/revsets>
Simon Sapin
rhg: Fall back to Python for unsupported revset syntax...
r47459 use crate::errors::HgError;
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 use crate::repo::Repo;
use crate::revlog::changelog::Changelog;
use crate::revlog::revlog::{Revlog, RevlogError};
use crate::revlog::NodePrefix;
Pulkit Goyal
rhg: raise wdir specific error for `hg debugdata`...
r47577 use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX};
use crate::Node;
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162
/// Resolve a query string into a single revision.
///
/// Only some of the revset language is implemented yet.
pub fn resolve_single(
input: &str,
repo: &Repo,
) -> Result<Revision, RevlogError> {
let changelog = Changelog::open(repo)?;
match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) {
Err(RevlogError::InvalidRevision) => {} // Try other syntax
result => return result,
}
if input == "null" {
return Ok(NULL_REVISION);
}
// TODO: support for the rest of the language here.
Simon Sapin
rhg: Fall back to Python for unsupported revset syntax...
r47459 Err(
HgError::unsupported(format!("cannot parse revset '{}'", input))
.into(),
)
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 }
/// Resolve the small subset of the language suitable for revlogs other than
/// the changelog, such as in `hg debugdata --manifest` CLI argument.
///
/// * A non-negative decimal integer for a revision number, or
/// * An hexadecimal string, for the unique node ID that starts with this
/// prefix
pub fn resolve_rev_number_or_hex_prefix(
input: &str,
revlog: &Revlog,
) -> Result<Revision, RevlogError> {
if let Ok(integer) = input.parse::<i32>() {
if integer >= 0 && revlog.has_rev(integer) {
return Ok(integer);
}
}
if let Ok(prefix) = NodePrefix::from_hex(input) {
Pulkit Goyal
rhg: raise wdir specific error for `hg debugdata`...
r47577 if prefix.is_prefix_of(&Node::from_hex(WORKING_DIRECTORY_HEX).unwrap())
{
return Err(RevlogError::WDirUnsupported);
}
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 return revlog.get_node_rev(prefix);
}
Err(RevlogError::InvalidRevision)
}