##// END OF EJS Templates
chgserver: respect detailed exit code in case of ConfigError...
chgserver: respect detailed exit code in case of ConfigError This effectively backs out 60523483897cf8caf7718aaf81c58d4d9fd5e1fa which was a bandaid. Martin yesterday fixed a similar failure which motivated me to fix it the correct way.

File last commit:

r46706:9eb07ab3 default
r46761:6383bb86 default
Show More
requirements.rs
76 lines | 2.5 KiB | application/rls-services+xml | RustLexer
Simon Sapin
requirements: move loading to hg-core and add parsing...
r46536 use std::io;
use std::path::Path;
#[derive(Debug)]
pub enum RequirementsError {
// TODO: include a path?
Io(io::Error),
/// The `requires` file is corrupted
Corrupted,
rust: fix non-utf8 char in requirements.rs...
r46570 /// The repository requires a feature that we don't support
Simon Sapin
requirements: move loading to hg-core and add parsing...
r46536 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
Simon Sapin
rhg: check that .hg/requires is ASCII...
r46550 if line[0].is_ascii_alphanumeric() && line.is_ascii() {
Simon Sapin
requirements: move loading to hg-core and add parsing...
r46536 Ok(String::from_utf8(line.into()).unwrap())
} else {
Err(())
}
})
.collect()
}
pub fn load(repo_root: &Path) -> Result<Vec<String>, RequirementsError> {
match std::fs::read(repo_root.join(".hg").join("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))?,
}
}
Simon Sapin
rhg: exit with relevant code for unsupported requirements...
r46549
pub fn check(repo_root: &Path) -> Result<(), RequirementsError> {
for feature in load(repo_root)? {
if !SUPPORTED.contains(&&*feature) {
rust: fix non-utf8 char in requirements.rs...
r46570 return Err(RequirementsError::Unsupported { feature });
Simon Sapin
rhg: exit with relevant code for unsupported requirements...
r46549 }
}
Ok(())
}
// TODO: set this to actually-supported features
const SUPPORTED: &[&str] = &[
"dotencode",
"fncache",
"generaldelta",
"revlogv1",
"sparserevlog",
"store",
Simon Sapin
rhg: use persistent nodemap when available...
r46706 // 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",
Simon Sapin
rhg: exit with relevant code for unsupported requirements...
r46549 ];