Skip to content
Snippets Groups Projects
Commit ead435aa5294 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.

Differential Revision: https://phab.mercurial-scm.org/D9397
parent 37bcd7f5a543
No related branches found
No related tags found
No related merge requests found
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 @@
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 @@
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 @@
.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 @@
("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 @@
$ 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment