##// END OF EJS Templates
rhg: Add support for automatic fallback to Python...
rhg: Add support for automatic fallback to Python `rhg` is a command-line application that can do a small subset of what `hg` can. It is written entirely in Rust, which avoids the cost of starting a Python interpreter and importing many Python modules. In a script that runs many `hg` commands, this cost can add up. However making users decide when to use `rhg` instead of `hg` is not practical as we want the subset of supported functionality to grow over time. Instead we introduce "fallback" behavior where, when `rhg` encounters something (a sub-command, a repository format, …) that is not implemented in Rust-only, it does nothing but silently start a subprocess of Python-based `hg` running the same command. That way `rhg` becomes a drop-in replacement for `hg` that sometimes goes faster. Whether Python is used should be an implementation detail not apparent to users (other than through speed). A new `fallback` value is added to the previously introduced `rhg.on-unsupported` configuration key. When in this mode, the new `rhg.fallback-executable` config is determine what command to use to run a Python-based `hg`. The previous `rhg.on-unsupported = abort-silent` configuration was designed to let a wrapper script call `rhg` and then fall back to `hg` based on the exit code. This is still available, but having fallback behavior built-in in rhg might be easier for users instead of leaving that script "as an exercise for the reader". Using a subprocess like this is not idea, especially when `rhg` is to be installed in `$PATH` as `hg`, since the other `hg.py` executable needs to still be available… somewhere. Eventually this could be replaced by using PyOxidizer to a have a single executable that embeds a Python interpreter, but only starts it when needed. Differential Revision: https://phab.mercurial-scm.org/D10093

File last commit:

r47405:b92083ad default
r47425:93e9f448 default
Show More
tests_support.rs
199 lines | 5.1 KiB | application/rls-services+xml | RustLexer
//! Supporting macros for `tests.rs` in the same directory.
//! See comments there for usage.
/// Python-like set literal
macro_rules! set {
(
$Type: ty {
$( $value: expr ),* $(,)?
}
) => {{
#[allow(unused_mut)]
let mut set = <$Type>::new();
$( set.insert($value); )*
set
}}
}
/// `{key => value}` map literal
macro_rules! map {
(
$Type: ty {
$( $key: expr => $value: expr ),* $(,)?
}
) => {{
#[allow(unused_mut)]
let mut set = <$Type>::new();
$( set.insert($key, $value); )*
set
}}
}
macro_rules! copy_source {
($rev: expr, $path: expr, $overwritten: tt) => {
CopySource {
rev: $rev,
path: $path,
overwritten: set!(OrdSet<Revision> $overwritten),
}
};
}
macro_rules! compare_value {
(
$merge_revision: expr,
$merge_case_for_dest: ident,
($min_rev: expr, $min_path: expr, $min_overwrite: tt),
($maj_rev: expr, $maj_path: expr, $maj_overwrite: tt) $(,)?
) => {
compare_value(
$merge_revision,
|| $merge_case_for_dest,
&copy_source!($min_rev, $min_path, $min_overwrite),
&copy_source!($maj_rev, $maj_path, $maj_overwrite),
)
};
}
macro_rules! tokenized_path_copies {
(
$path_map: ident, {$(
$dest: expr => (
$src_rev: expr,
$src_path: expr,
$src_overwrite: tt
)
),*}
$(,)*
) => {
map!(InternalPathCopies {$(
$path_map.tokenize(HgPath::new($dest)) =>
copy_source!(
$src_rev,
Option::map($src_path, |p: &str| {
$path_map.tokenize(HgPath::new(p))
}),
$src_overwrite
)
)*})
}
}
macro_rules! merge_case_callback {
(
$( $merge_path: expr => $merge_case: ident ),*
$(,)?
) => {
#[allow(unused)]
|merge_path| -> MergeCase {
$(
if (merge_path == HgPath::new($merge_path)) {
return $merge_case
}
)*
MergeCase::Normal
}
};
}
macro_rules! merge_copies_dict {
(
$current_merge: expr,
$minor_copies: tt,
$major_copies: tt,
$get_merge_case: tt $(,)?
) => {
{
#[allow(unused_mut)]
let mut map = TwoWayPathMap::default();
let minor = tokenized_path_copies!(map, $minor_copies);
let major = tokenized_path_copies!(map, $major_copies);
merge_copies_dict(
&map, $current_merge, minor, major,
merge_case_callback! $get_merge_case,
)
.into_iter()
.map(|(token, source)| {
(
map.untokenize(token).to_string(),
(
source.rev,
source.path.map(|t| map.untokenize(t).to_string()),
source.overwritten.into_iter().collect(),
),
)
})
.collect::<OrdMap<_, _>>()
}
};
}
macro_rules! internal_path_copies {
(
$(
$dest: expr => (
$src_rev: expr,
$src_path: expr,
$src_overwrite: tt $(,)?
)
),*
$(,)*
) => {
map!(OrdMap<_, _> {$(
String::from($dest) => (
$src_rev,
$src_path,
set!(OrdSet<Revision> $src_overwrite)
)
),*})
};
}
macro_rules! combine_changeset_copies {
(
$children_count: tt,
[
$(
{
rev: $rev: expr,
p1: $p1: expr,
p2: $p2: expr,
actions: [
$(
$Action: ident($( $action_path: expr ),+)
),*
$(,)?
],
merge_cases: $merge: tt
$(,)?
}
),*
$(,)?
],
$target_rev: expr $(,)*
) => {{
let count = map!(HashMap<Revision, usize> $children_count);
let mut combine_changeset_copies = CombineChangesetCopies::new(count);
$(
let actions = vec![$(
$Action($( HgPath::new($action_path) ),*)
),*];
combine_changeset_copies.add_revision_inner(
$rev, $p1, $p2, actions.into_iter(),
merge_case_callback! $merge
);
)*
combine_changeset_copies.finish($target_rev)
}};
}
macro_rules! path_copies {
(
$( $expected_destination: expr => $expected_source: expr ),* $(,)?
) => {
map!(PathCopies {$(
HgPath::new($expected_destination).to_owned()
=> HgPath::new($expected_source).to_owned(),
),*})
};
}