##// END OF EJS Templates
rhg: add a `debugrequirements` subcommand...
rhg: add a `debugrequirements` subcommand For now it only prints the contents of `.hg/requires` as-is, without parsing. Differential Revision: https://phab.mercurial-scm.org/D9397

File last commit:

r46535:ead435aa default
r46535:ead435aa default
Show More
debugrequirements.rs
40 lines | 1.3 KiB | application/rls-services+xml | RustLexer
/ rust / rhg / src / commands / debugrequirements.rs
use crate::commands::Command;
use crate::error::{CommandError, CommandErrorKind};
use crate::ui::Ui;
use hg::operations::FindRoot;
pub const HELP_TEXT: &str = "
Print the current repo requirements.
";
pub struct DebugRequirementsCommand {}
impl DebugRequirementsCommand {
pub fn new() -> Self {
DebugRequirementsCommand {}
}
}
impl Command for DebugRequirementsCommand {
fn run(&self, ui: &Ui) -> Result<(), CommandError> {
let root = FindRoot::new().run()?;
let requires = root.join(".hg").join("requires");
let requirements = match std::fs::read(requires) {
Ok(bytes) => bytes,
// 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 => Vec::new(),
Err(error) => Err(CommandErrorKind::FileError(error))?,
};
ui.write_stdout(&requirements)?;
Ok(())
}
}