Show More
@@ -1,3 +1,4 b'' | |||||
|
1 | use crate::config::Config; | |||
1 | use crate::errors::{HgError, IoResultExt}; |
|
2 | use crate::errors::{HgError, IoResultExt}; | |
2 | use crate::requirements; |
|
3 | use crate::requirements; | |
3 | use crate::utils::files::get_path_from_bytes; |
|
4 | use crate::utils::files::get_path_from_bytes; | |
@@ -31,7 +32,7 b" pub(crate) struct Vfs<'a> {" | |||||
31 | impl Repo { |
|
32 | impl Repo { | |
32 | /// Search the current directory and its ancestores for a repository: |
|
33 | /// Search the current directory and its ancestores for a repository: | |
33 | /// a working directory that contains a `.hg` sub-directory. |
|
34 | /// a working directory that contains a `.hg` sub-directory. | |
34 | pub fn find() -> Result<Self, RepoFindError> { |
|
35 | pub fn find(_config: &Config) -> Result<Self, RepoFindError> { | |
35 | let current_directory = crate::utils::current_dir()?; |
|
36 | let current_directory = crate::utils::current_dir()?; | |
36 | // ancestors() is inclusive: it first yields `current_directory` as-is. |
|
37 | // ancestors() is inclusive: it first yields `current_directory` as-is. | |
37 | for ancestor in current_directory.ancestors() { |
|
38 | for ancestor in current_directory.ancestors() { |
@@ -5,10 +5,11 b' pub mod files;' | |||||
5 | pub mod root; |
|
5 | pub mod root; | |
6 | use crate::error::CommandError; |
|
6 | use crate::error::CommandError; | |
7 | use crate::ui::Ui; |
|
7 | use crate::ui::Ui; | |
|
8 | use hg::config::Config; | |||
8 |
|
9 | |||
9 | /// The common trait for rhg commands |
|
10 | /// The common trait for rhg commands | |
10 | /// |
|
11 | /// | |
11 | /// Normalize the interface of the commands provided by rhg |
|
12 | /// Normalize the interface of the commands provided by rhg | |
12 | pub trait Command { |
|
13 | pub trait Command { | |
13 | fn run(&self, ui: &Ui) -> Result<(), CommandError>; |
|
14 | fn run(&self, ui: &Ui, config: &Config) -> Result<(), CommandError>; | |
14 | } |
|
15 | } |
@@ -1,6 +1,7 b'' | |||||
1 | use crate::commands::Command; |
|
1 | use crate::commands::Command; | |
2 | use crate::error::CommandError; |
|
2 | use crate::error::CommandError; | |
3 | use crate::ui::Ui; |
|
3 | use crate::ui::Ui; | |
|
4 | use hg::config::Config; | |||
4 | use hg::operations::cat; |
|
5 | use hg::operations::cat; | |
5 | use hg::repo::Repo; |
|
6 | use hg::repo::Repo; | |
6 | use hg::utils::hg_path::HgPathBuf; |
|
7 | use hg::utils::hg_path::HgPathBuf; | |
@@ -29,8 +30,8 b" impl<'a> CatCommand<'a> {" | |||||
29 |
|
30 | |||
30 | impl<'a> Command for CatCommand<'a> { |
|
31 | impl<'a> Command for CatCommand<'a> { | |
31 | #[timed] |
|
32 | #[timed] | |
32 | fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
|
33 | fn run(&self, ui: &Ui, config: &Config) -> Result<(), CommandError> { | |
33 | let repo = Repo::find()?; |
|
34 | let repo = Repo::find(config)?; | |
34 | let cwd = hg::utils::current_dir()?; |
|
35 | let cwd = hg::utils::current_dir()?; | |
35 |
|
36 | |||
36 | let mut files = vec![]; |
|
37 | let mut files = vec![]; |
@@ -1,6 +1,7 b'' | |||||
1 | use crate::commands::Command; |
|
1 | use crate::commands::Command; | |
2 | use crate::error::CommandError; |
|
2 | use crate::error::CommandError; | |
3 | use crate::ui::Ui; |
|
3 | use crate::ui::Ui; | |
|
4 | use hg::config::Config; | |||
4 | use hg::operations::{debug_data, DebugDataKind}; |
|
5 | use hg::operations::{debug_data, DebugDataKind}; | |
5 | use hg::repo::Repo; |
|
6 | use hg::repo::Repo; | |
6 | use micro_timer::timed; |
|
7 | use micro_timer::timed; | |
@@ -22,8 +23,8 b" impl<'a> DebugDataCommand<'a> {" | |||||
22 |
|
23 | |||
23 | impl<'a> Command for DebugDataCommand<'a> { |
|
24 | impl<'a> Command for DebugDataCommand<'a> { | |
24 | #[timed] |
|
25 | #[timed] | |
25 | fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
|
26 | fn run(&self, ui: &Ui, config: &Config) -> Result<(), CommandError> { | |
26 | let repo = Repo::find()?; |
|
27 | let repo = Repo::find(config)?; | |
27 | let data = debug_data(&repo, self.rev, self.kind) |
|
28 | let data = debug_data(&repo, self.rev, self.kind) | |
28 | .map_err(|e| (e, self.rev))?; |
|
29 | .map_err(|e| (e, self.rev))?; | |
29 |
|
30 |
@@ -1,6 +1,7 b'' | |||||
1 | use crate::commands::Command; |
|
1 | use crate::commands::Command; | |
2 | use crate::error::CommandError; |
|
2 | use crate::error::CommandError; | |
3 | use crate::ui::Ui; |
|
3 | use crate::ui::Ui; | |
|
4 | use hg::config::Config; | |||
4 | use hg::repo::Repo; |
|
5 | use hg::repo::Repo; | |
5 |
|
6 | |||
6 | pub const HELP_TEXT: &str = " |
|
7 | pub const HELP_TEXT: &str = " | |
@@ -16,8 +17,8 b' impl DebugRequirementsCommand {' | |||||
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, config: &Config) -> Result<(), CommandError> { | |
20 | let repo = Repo::find()?; |
|
21 | let repo = Repo::find(config)?; | |
21 | let mut output = String::new(); |
|
22 | let mut output = String::new(); | |
22 | let mut requirements: Vec<_> = repo.requirements().iter().collect(); |
|
23 | let mut requirements: Vec<_> = repo.requirements().iter().collect(); | |
23 | requirements.sort(); |
|
24 | requirements.sort(); |
@@ -1,6 +1,7 b'' | |||||
1 | use crate::commands::Command; |
|
1 | use crate::commands::Command; | |
2 | use crate::error::CommandError; |
|
2 | use crate::error::CommandError; | |
3 | use crate::ui::Ui; |
|
3 | use crate::ui::Ui; | |
|
4 | use hg::config::Config; | |||
4 | use hg::operations::list_rev_tracked_files; |
|
5 | use hg::operations::list_rev_tracked_files; | |
5 | use hg::operations::Dirstate; |
|
6 | use hg::operations::Dirstate; | |
6 | use hg::repo::Repo; |
|
7 | use hg::repo::Repo; | |
@@ -46,8 +47,8 b" impl<'a> FilesCommand<'a> {" | |||||
46 | } |
|
47 | } | |
47 |
|
48 | |||
48 | impl<'a> Command for FilesCommand<'a> { |
|
49 | impl<'a> Command for FilesCommand<'a> { | |
49 | fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
|
50 | fn run(&self, ui: &Ui, config: &Config) -> Result<(), CommandError> { | |
50 | let repo = Repo::find()?; |
|
51 | let repo = Repo::find(config)?; | |
51 | if let Some(rev) = self.rev { |
|
52 | if let Some(rev) = self.rev { | |
52 | let files = |
|
53 | let files = | |
53 | list_rev_tracked_files(&repo, rev).map_err(|e| (e, rev))?; |
|
54 | list_rev_tracked_files(&repo, rev).map_err(|e| (e, rev))?; |
@@ -2,6 +2,7 b' use crate::commands::Command;' | |||||
2 | use crate::error::CommandError; |
|
2 | use crate::error::CommandError; | |
3 | use crate::ui::Ui; |
|
3 | use crate::ui::Ui; | |
4 | use format_bytes::format_bytes; |
|
4 | use format_bytes::format_bytes; | |
|
5 | use hg::config::Config; | |||
5 | use hg::repo::Repo; |
|
6 | use hg::repo::Repo; | |
6 | use hg::utils::files::get_bytes_from_path; |
|
7 | use hg::utils::files::get_bytes_from_path; | |
7 |
|
8 | |||
@@ -20,8 +21,8 b' impl RootCommand {' | |||||
20 | } |
|
21 | } | |
21 |
|
22 | |||
22 | impl Command for RootCommand { |
|
23 | impl Command for RootCommand { | |
23 | fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
|
24 | fn run(&self, ui: &Ui, config: &Config) -> Result<(), CommandError> { | |
24 | let repo = Repo::find()?; |
|
25 | let repo = Repo::find(config)?; | |
25 | let bytes = get_bytes_from_path(repo.working_directory_path()); |
|
26 | let bytes = get_bytes_from_path(repo.working_directory_path()); | |
26 | ui.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?; |
|
27 | ui.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?; | |
27 | Ok(()) |
|
28 | Ok(()) |
@@ -1,6 +1,7 b'' | |||||
1 | use crate::ui::utf8_to_local; |
|
1 | use crate::ui::utf8_to_local; | |
2 | use crate::ui::UiError; |
|
2 | use crate::ui::UiError; | |
3 | use format_bytes::format_bytes; |
|
3 | use format_bytes::format_bytes; | |
|
4 | use hg::config::{ConfigError, ConfigParseError}; | |||
4 | use hg::errors::HgError; |
|
5 | use hg::errors::HgError; | |
5 | use hg::repo::RepoFindError; |
|
6 | use hg::repo::RepoFindError; | |
6 | use hg::revlog::revlog::RevlogError; |
|
7 | use hg::revlog::revlog::RevlogError; | |
@@ -66,6 +67,36 b' impl From<RepoFindError> for CommandErro' | |||||
66 | } |
|
67 | } | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
|
70 | impl From<ConfigError> for CommandError { | |||
|
71 | fn from(error: ConfigError) -> Self { | |||
|
72 | match error { | |||
|
73 | ConfigError::Parse(ConfigParseError { | |||
|
74 | origin, | |||
|
75 | line, | |||
|
76 | bytes, | |||
|
77 | }) => { | |||
|
78 | let line_message = if let Some(line_number) = line { | |||
|
79 | format_bytes!( | |||
|
80 | b" at line {}", | |||
|
81 | line_number.to_string().into_bytes() | |||
|
82 | ) | |||
|
83 | } else { | |||
|
84 | Vec::new() | |||
|
85 | }; | |||
|
86 | CommandError::Abort { | |||
|
87 | message: format_bytes!( | |||
|
88 | b"config parse error in {}{}: '{}'", | |||
|
89 | origin.to_bytes(), | |||
|
90 | line_message, | |||
|
91 | bytes | |||
|
92 | ), | |||
|
93 | } | |||
|
94 | } | |||
|
95 | ConfigError::Other(error) => error.into(), | |||
|
96 | } | |||
|
97 | } | |||
|
98 | } | |||
|
99 | ||||
69 | impl From<(RevlogError, &str)> for CommandError { |
|
100 | impl From<(RevlogError, &str)> for CommandError { | |
70 | fn from((err, rev): (RevlogError, &str)) -> CommandError { |
|
101 | fn from((err, rev): (RevlogError, &str)) -> CommandError { | |
71 | match err { |
|
102 | match err { |
@@ -123,20 +123,23 b' fn match_subcommand(' | |||||
123 | matches: ArgMatches, |
|
123 | matches: ArgMatches, | |
124 | ui: &ui::Ui, |
|
124 | ui: &ui::Ui, | |
125 | ) -> Result<(), CommandError> { |
|
125 | ) -> Result<(), CommandError> { | |
|
126 | let config = hg::config::Config::load()?; | |||
|
127 | ||||
126 | match matches.subcommand() { |
|
128 | match matches.subcommand() { | |
127 | ("root", _) => commands::root::RootCommand::new().run(&ui), |
|
129 | ("root", _) => commands::root::RootCommand::new().run(&ui, &config), | |
128 | ("files", Some(matches)) => { |
|
130 | ("files", Some(matches)) => { | |
129 | commands::files::FilesCommand::try_from(matches)?.run(&ui) |
|
131 | commands::files::FilesCommand::try_from(matches)?.run(&ui, &config) | |
130 | } |
|
132 | } | |
131 | ("cat", Some(matches)) => { |
|
133 | ("cat", Some(matches)) => { | |
132 | commands::cat::CatCommand::try_from(matches)?.run(&ui) |
|
134 | commands::cat::CatCommand::try_from(matches)?.run(&ui, &config) | |
133 | } |
|
135 | } | |
134 | ("debugdata", Some(matches)) => { |
|
136 | ("debugdata", Some(matches)) => { | |
135 |
commands::debugdata::DebugDataCommand::try_from(matches)? |
|
137 | commands::debugdata::DebugDataCommand::try_from(matches)? | |
|
138 | .run(&ui, &config) | |||
136 | } |
|
139 | } | |
137 | ("debugrequirements", _) => { |
|
140 | ("debugrequirements", _) => { | |
138 | commands::debugrequirements::DebugRequirementsCommand::new() |
|
141 | commands::debugrequirements::DebugRequirementsCommand::new() | |
139 | .run(&ui) |
|
142 | .run(&ui, &config) | |
140 | } |
|
143 | } | |
141 | _ => unreachable!(), // Because of AppSettings::SubcommandRequired, |
|
144 | _ => unreachable!(), // Because of AppSettings::SubcommandRequired, | |
142 | } |
|
145 | } |
General Comments 0
You need to be logged in to leave comments.
Login now