##// END OF EJS Templates
hooks: introduce a `:run-with-plain` option for hooks...
hooks: introduce a `:run-with-plain` option for hooks This option control if HGPLAIN should be set or not for the hooks. This is the first step to give user some control of the HGPLAIN setting for they hooks. Some hooks (eg: consistency checking) deserve to be run with HGPLAIN, some other (eg: user set visual helper) might need to respect the user config and setting. So both usage are valid and we need to restore the ability to run -without- HGPLAIN that got lost in Mercurial 5.7. This does not offer a way to restore the pre-5.7 behavior yet (respect whatever HGPLAIN setting from the shell), this will be dealt with in the next changeset. The option name is a bit verbose because implementing this highlighs the need for another option: `:run-if-plain`. That would make it possible for some hooks to be easily disabled if HG PLAIN is set. However such option would be a new feature, not something introduced to mitigate a behavior change introduced in 5.7, so the `:run-if-plain` option belong to the default branch and is not part of this series. Differential Revision: https://phab.mercurial-scm.org/D9981

File last commit:

r47191:95b27628 default
r47242:7289eac7 stable
Show More
requirements.rs
76 lines | 2.4 KiB | application/rls-services+xml | RustLexer
use crate::repo::Repo;
use std::io;
#[derive(Debug)]
pub enum RequirementsError {
// TODO: include a path?
Io(io::Error),
/// The `requires` file is corrupted
Corrupted,
/// The repository requires a feature that we don't support
Unsupported {
feature: String,
},
}
fn parse(bytes: &[u8]) -> Result<Vec<String>, ()> {
// The Python code reading this file uses `str.splitlines`
// which looks for a number of line separators (even including a couple of
// non-ASCII ones), but Python code writing it always uses `\n`.
let lines = bytes.split(|&byte| byte == b'\n');
lines
.filter(|line| !line.is_empty())
.map(|line| {
// Python uses Unicode `str.isalnum` but feature names are all
// ASCII
if line[0].is_ascii_alphanumeric() && line.is_ascii() {
Ok(String::from_utf8(line.into()).unwrap())
} else {
Err(())
}
})
.collect()
}
pub fn load(repo: &Repo) -> Result<Vec<String>, RequirementsError> {
match repo.hg_vfs().read("requires") {
Ok(bytes) => parse(&bytes).map_err(|()| RequirementsError::Corrupted),
// Treat a missing file the same as an empty file.
// From `mercurial/localrepo.py`:
// > requires file contains a newline-delimited list of
// > features/capabilities the opener (us) must have in order to use
// > the repository. This file was introduced in Mercurial 0.9.2,
// > which means very old repositories may not have one. We assume
// > a missing file translates to no requirements.
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
Ok(Vec::new())
}
Err(error) => Err(RequirementsError::Io(error))?,
}
}
pub fn check(repo: &Repo) -> Result<(), RequirementsError> {
for feature in load(repo)? {
if !SUPPORTED.contains(&&*feature) {
return Err(RequirementsError::Unsupported { feature });
}
}
Ok(())
}
// TODO: set this to actually-supported features
const SUPPORTED: &[&str] = &[
"dotencode",
"fncache",
"generaldelta",
"revlogv1",
"sparserevlog",
"store",
// As of this writing everything rhg does is read-only.
// When it starts writing to the repository, it’ll need to either keep the
// persistent nodemap up to date or remove this entry:
"persistent-nodemap",
];