author | Simon Sapin <simon-commits@exyr.org> |
Tue, 24 Nov 2020 15:11:58 +0100 | |
changeset 45923 | ead435aa5294 |
child 45924 | a2eda1ff22aa |
permissions | -rw-r--r-- |
45923
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
1 |
use crate::commands::Command; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
2 |
use crate::error::{CommandError, CommandErrorKind}; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
3 |
use crate::ui::Ui; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
4 |
use hg::operations::FindRoot; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
5 |
|
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
6 |
pub const HELP_TEXT: &str = " |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
7 |
Print the current repo requirements. |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
8 |
"; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
9 |
|
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
10 |
pub struct DebugRequirementsCommand {} |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
11 |
|
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
12 |
impl DebugRequirementsCommand { |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
13 |
pub fn new() -> Self { |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
14 |
DebugRequirementsCommand {} |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
15 |
} |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
16 |
} |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
17 |
|
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
18 |
impl Command for DebugRequirementsCommand { |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
19 |
fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
20 |
let root = FindRoot::new().run()?; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
21 |
let requires = root.join(".hg").join("requires"); |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
22 |
let requirements = match std::fs::read(requires) { |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
23 |
Ok(bytes) => bytes, |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
24 |
|
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
25 |
// Treat a missing file the same as an empty file. |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
26 |
// From `mercurial/localrepo.py`: |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
27 |
// > requires file contains a newline-delimited list of |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
28 |
// > features/capabilities the opener (us) must have in order to use |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
29 |
// > the repository. This file was introduced in Mercurial 0.9.2, |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
30 |
// > which means very old repositories may not have one. We assume |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
31 |
// > a missing file translates to no requirements. |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
32 |
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Vec::new(), |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
33 |
|
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
34 |
Err(error) => Err(CommandErrorKind::FileError(error))?, |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
35 |
}; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
36 |
|
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
37 |
ui.write_stdout(&requirements)?; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
38 |
Ok(()) |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
39 |
} |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
40 |
} |