Mercurial > hg
comparison rust/rhg/src/commands/debugrequirements.rs @ 45924:a2eda1ff22aa
requirements: move loading to hg-core and add parsing
No functional change, checking comes later.
Differential Revision: https://phab.mercurial-scm.org/D9398
author | Simon Sapin <simon-commits@exyr.org> |
---|---|
date | Tue, 24 Nov 2020 17:49:16 +0100 |
parents | ead435aa5294 |
children | dca9cb99971c |
comparison
equal
deleted
inserted
replaced
45923:ead435aa5294 | 45924:a2eda1ff22aa |
---|---|
1 use crate::commands::Command; | 1 use crate::commands::Command; |
2 use crate::error::{CommandError, CommandErrorKind}; | 2 use crate::error::CommandError; |
3 use crate::ui::Ui; | 3 use crate::ui::Ui; |
4 use hg::operations::FindRoot; | 4 use hg::operations::FindRoot; |
5 use hg::requirements; | |
5 | 6 |
6 pub const HELP_TEXT: &str = " | 7 pub const HELP_TEXT: &str = " |
7 Print the current repo requirements. | 8 Print the current repo requirements. |
8 "; | 9 "; |
9 | 10 |
16 } | 17 } |
17 | 18 |
18 impl Command for DebugRequirementsCommand { | 19 impl Command for DebugRequirementsCommand { |
19 fn run(&self, ui: &Ui) -> Result<(), CommandError> { | 20 fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
20 let root = FindRoot::new().run()?; | 21 let root = FindRoot::new().run()?; |
21 let requires = root.join(".hg").join("requires"); | 22 let mut output = String::new(); |
22 let requirements = match std::fs::read(requires) { | 23 for req in requirements::load(&root)? { |
23 Ok(bytes) => bytes, | 24 output.push_str(&req); |
24 | 25 output.push('\n'); |
25 // Treat a missing file the same as an empty file. | 26 } |
26 // From `mercurial/localrepo.py`: | 27 ui.write_stdout(output.as_bytes())?; |
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(()) | 28 Ok(()) |
39 } | 29 } |
40 } | 30 } |