##// 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:

r47172:43d63979 default
r47425:93e9f448 default
Show More
changelog.rs
61 lines | 1.8 KiB | application/rls-services+xml | RustLexer
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 use crate::errors::HgError;
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 use crate::repo::Repo;
Antoine Cezar
hg-core: add `Changlog` a specialized `Revlog`...
r46103 use crate::revlog::revlog::{Revlog, RevlogError};
Simon Sapin
rust: Make NodePrefix allocation-free and Copy, remove NodePrefixRef...
r47160 use crate::revlog::NodePrefix;
Antoine Cezar
hg-core: add `Changlog` a specialized `Revlog`...
r46103 use crate::revlog::Revision;
/// A specialized `Revlog` to work with `changelog` data format.
pub struct Changelog {
/// The generic `revlog` format.
Simon Sapin
rhg: centralize parsing of `--rev` CLI arguments...
r47162 pub(crate) revlog: Revlog,
Antoine Cezar
hg-core: add `Changlog` a specialized `Revlog`...
r46103 }
impl Changelog {
/// Open the `changelog` of a repository given by its root.
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 pub fn open(repo: &Repo) -> Result<Self, RevlogError> {
let revlog = Revlog::open(repo, "00changelog.i", None)?;
Antoine Cezar
hg-core: add `Changlog` a specialized `Revlog`...
r46103 Ok(Self { revlog })
}
/// Return the `ChangelogEntry` a given node id.
pub fn get_node(
&self,
Simon Sapin
rust: Make NodePrefix allocation-free and Copy, remove NodePrefixRef...
r47160 node: NodePrefix,
Antoine Cezar
hg-core: add `Changlog` a specialized `Revlog`...
r46103 ) -> Result<ChangelogEntry, RevlogError> {
let rev = self.revlog.get_node_rev(node)?;
self.get_rev(rev)
}
/// Return the `ChangelogEntry` of a given node revision.
pub fn get_rev(
&self,
rev: Revision,
) -> Result<ChangelogEntry, RevlogError> {
let bytes = self.revlog.get_rev_data(rev)?;
Ok(ChangelogEntry { bytes })
}
}
/// `Changelog` entry which knows how to interpret the `changelog` data bytes.
#[derive(Debug)]
pub struct ChangelogEntry {
/// The data bytes of the `changelog` entry.
bytes: Vec<u8>,
}
impl ChangelogEntry {
/// Return an iterator over the lines of the entry.
pub fn lines(&self) -> impl Iterator<Item = &[u8]> {
self.bytes
.split(|b| b == &b'\n')
.filter(|line| !line.is_empty())
}
/// Return the node id of the `manifest` referenced by this `changelog`
/// entry.
pub fn manifest_node(&self) -> Result<&[u8], RevlogError> {
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 self.lines()
.next()
.ok_or_else(|| HgError::corrupted("empty changelog entry").into())
Antoine Cezar
hg-core: add `Changlog` a specialized `Revlog`...
r46103 }
}