Read about our upcoming Code of Conduct on this issue

Commit 83f19ae0 authored by Simon Sapin's avatar Simon Sapin
Browse files

rhg: add a `debugrequirements` subcommand

For now it only prints the contents of `.hg/requires` as-is, without parsing.
parent 4b4160a83303
pub mod cat;
pub mod debugdata;
pub mod debugrequirements;
pub mod files;
pub mod root;
use crate::error::CommandError;
......
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(())
}
}
......@@ -12,6 +12,9 @@ pub enum CommandErrorKind {
RootNotFound(PathBuf),
/// The current directory cannot be found
CurrentDirNotFound(std::io::Error),
/// Error while reading or writing a file
// TODO: add the file name/path?
FileError(std::io::Error),
/// The standard output stream cannot be written to
StdoutError,
/// The standard error stream cannot be written to
......@@ -27,6 +30,7 @@ impl CommandErrorKind {
match self {
CommandErrorKind::RootNotFound(_) => exitcode::ABORT,
CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT,
CommandErrorKind::FileError(_) => exitcode::ABORT,
CommandErrorKind::StdoutError => exitcode::ABORT,
CommandErrorKind::StderrError => exitcode::ABORT,
CommandErrorKind::Abort(_) => exitcode::ABORT,
......
......@@ -83,6 +83,10 @@ fn main() {
.required(true)
.value_name("REV"),
),
)
.subcommand(
SubCommand::with_name("debugrequirements")
.about(commands::debugrequirements::HELP_TEXT),
);
let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
......@@ -124,6 +128,10 @@ fn match_subcommand(
("debugdata", Some(matches)) => {
commands::debugdata::DebugDataCommand::try_from(matches)?.run(&ui)
}
("debugrequirements", _) => {
commands::debugrequirements::DebugRequirementsCommand::new()
.run(&ui)
}
_ => unreachable!(), // Because of AppSettings::SubcommandRequired,
}
}
......
......@@ -115,3 +115,12 @@ Cat copied file should not display copy metadata
$ hg commit -m "add copy of original"
$ rhg cat -r 1 copy_of_original
original content
Requirements
$ rhg debugrequirements
dotencode
fncache
generaldelta
revlogv1
sparserevlog
store
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment