Show More
@@ -0,0 +1,40 b'' | |||||
|
1 | use crate::commands::Command; | |||
|
2 | use crate::error::{CommandError, CommandErrorKind}; | |||
|
3 | use crate::ui::Ui; | |||
|
4 | use hg::operations::FindRoot; | |||
|
5 | ||||
|
6 | pub const HELP_TEXT: &str = " | |||
|
7 | Print the current repo requirements. | |||
|
8 | "; | |||
|
9 | ||||
|
10 | pub struct DebugRequirementsCommand {} | |||
|
11 | ||||
|
12 | impl DebugRequirementsCommand { | |||
|
13 | pub fn new() -> Self { | |||
|
14 | DebugRequirementsCommand {} | |||
|
15 | } | |||
|
16 | } | |||
|
17 | ||||
|
18 | impl Command for DebugRequirementsCommand { | |||
|
19 | fn run(&self, ui: &Ui) -> Result<(), CommandError> { | |||
|
20 | let root = FindRoot::new().run()?; | |||
|
21 | let requires = root.join(".hg").join("requires"); | |||
|
22 | let requirements = match std::fs::read(requires) { | |||
|
23 | Ok(bytes) => bytes, | |||
|
24 | ||||
|
25 | // Treat a missing file the same as an empty file. | |||
|
26 | // From `mercurial/localrepo.py`: | |||
|
27 | // > requires file contains a newline-delimited list of | |||
|
28 | // > features/capabilities the opener (us) must have in order to use | |||
|
29 | // > the repository. This file was introduced in Mercurial 0.9.2, | |||
|
30 | // > which means very old repositories may not have one. We assume | |||
|
31 | // > a missing file translates to no requirements. | |||
|
32 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => Vec::new(), | |||
|
33 | ||||
|
34 | Err(error) => Err(CommandErrorKind::FileError(error))?, | |||
|
35 | }; | |||
|
36 | ||||
|
37 | ui.write_stdout(&requirements)?; | |||
|
38 | Ok(()) | |||
|
39 | } | |||
|
40 | } |
@@ -1,5 +1,6 b'' | |||||
1 | pub mod cat; |
|
1 | pub mod cat; | |
2 | pub mod debugdata; |
|
2 | pub mod debugdata; | |
|
3 | pub mod debugrequirements; | |||
3 | pub mod files; |
|
4 | pub mod files; | |
4 | pub mod root; |
|
5 | pub mod root; | |
5 | use crate::error::CommandError; |
|
6 | use crate::error::CommandError; |
@@ -12,6 +12,9 b' pub enum CommandErrorKind {' | |||||
12 | RootNotFound(PathBuf), |
|
12 | RootNotFound(PathBuf), | |
13 | /// The current directory cannot be found |
|
13 | /// The current directory cannot be found | |
14 | CurrentDirNotFound(std::io::Error), |
|
14 | CurrentDirNotFound(std::io::Error), | |
|
15 | /// Error while reading or writing a file | |||
|
16 | // TODO: add the file name/path? | |||
|
17 | FileError(std::io::Error), | |||
15 | /// The standard output stream cannot be written to |
|
18 | /// The standard output stream cannot be written to | |
16 | StdoutError, |
|
19 | StdoutError, | |
17 | /// The standard error stream cannot be written to |
|
20 | /// The standard error stream cannot be written to | |
@@ -27,6 +30,7 b' impl CommandErrorKind {' | |||||
27 | match self { |
|
30 | match self { | |
28 | CommandErrorKind::RootNotFound(_) => exitcode::ABORT, |
|
31 | CommandErrorKind::RootNotFound(_) => exitcode::ABORT, | |
29 | CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT, |
|
32 | CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT, | |
|
33 | CommandErrorKind::FileError(_) => exitcode::ABORT, | |||
30 | CommandErrorKind::StdoutError => exitcode::ABORT, |
|
34 | CommandErrorKind::StdoutError => exitcode::ABORT, | |
31 | CommandErrorKind::StderrError => exitcode::ABORT, |
|
35 | CommandErrorKind::StderrError => exitcode::ABORT, | |
32 | CommandErrorKind::Abort(_) => exitcode::ABORT, |
|
36 | CommandErrorKind::Abort(_) => exitcode::ABORT, |
@@ -83,6 +83,10 b' fn main() {' | |||||
83 | .required(true) |
|
83 | .required(true) | |
84 | .value_name("REV"), |
|
84 | .value_name("REV"), | |
85 | ), |
|
85 | ), | |
|
86 | ) | |||
|
87 | .subcommand( | |||
|
88 | SubCommand::with_name("debugrequirements") | |||
|
89 | .about(commands::debugrequirements::HELP_TEXT), | |||
86 | ); |
|
90 | ); | |
87 |
|
91 | |||
88 | let matches = app.clone().get_matches_safe().unwrap_or_else(|err| { |
|
92 | let matches = app.clone().get_matches_safe().unwrap_or_else(|err| { | |
@@ -124,6 +128,10 b' fn match_subcommand(' | |||||
124 | ("debugdata", Some(matches)) => { |
|
128 | ("debugdata", Some(matches)) => { | |
125 | commands::debugdata::DebugDataCommand::try_from(matches)?.run(&ui) |
|
129 | commands::debugdata::DebugDataCommand::try_from(matches)?.run(&ui) | |
126 | } |
|
130 | } | |
|
131 | ("debugrequirements", _) => { | |||
|
132 | commands::debugrequirements::DebugRequirementsCommand::new() | |||
|
133 | .run(&ui) | |||
|
134 | } | |||
127 | _ => unreachable!(), // Because of AppSettings::SubcommandRequired, |
|
135 | _ => unreachable!(), // Because of AppSettings::SubcommandRequired, | |
128 | } |
|
136 | } | |
129 | } |
|
137 | } |
@@ -115,3 +115,12 b' Cat copied file should not display copy ' | |||||
115 | $ hg commit -m "add copy of original" |
|
115 | $ hg commit -m "add copy of original" | |
116 | $ rhg cat -r 1 copy_of_original |
|
116 | $ rhg cat -r 1 copy_of_original | |
117 | original content |
|
117 | original content | |
|
118 | ||||
|
119 | Requirements | |||
|
120 | $ rhg debugrequirements | |||
|
121 | dotencode | |||
|
122 | fncache | |||
|
123 | generaldelta | |||
|
124 | revlogv1 | |||
|
125 | sparserevlog | |||
|
126 | store |
General Comments 0
You need to be logged in to leave comments.
Login now