Show More
@@ -20,9 +20,9 b' use crate::utils::hg_path::{HgPath, HgPa' | |||
|
20 | 20 | |
|
21 | 21 | const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n']; |
|
22 | 22 | |
|
23 | /// Kind of error encountered by `CatRev` | |
|
23 | /// Error type for `cat` | |
|
24 | 24 | #[derive(Debug)] |
|
25 |
pub enum CatRevError |
|
|
25 | pub enum CatRevError { | |
|
26 | 26 | /// Error when reading a `revlog` file. |
|
27 | 27 | IoError(std::io::Error), |
|
28 | 28 | /// The revision has not been found. |
@@ -37,34 +37,20 b' pub enum CatRevErrorKind {' | |||
|
37 | 37 | UnknowRevlogDataFormat(u8), |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | /// A `CatRev` error | |
|
41 | #[derive(Debug)] | |
|
42 | pub struct CatRevError { | |
|
43 | /// Kind of error encountered by `CatRev` | |
|
44 | pub kind: CatRevErrorKind, | |
|
45 | } | |
|
46 | ||
|
47 | impl From<CatRevErrorKind> for CatRevError { | |
|
48 | fn from(kind: CatRevErrorKind) -> Self { | |
|
49 | CatRevError { kind } | |
|
50 | } | |
|
51 | } | |
|
52 | ||
|
53 | 40 | impl From<RevlogError> for CatRevError { |
|
54 | 41 | fn from(err: RevlogError) -> Self { |
|
55 | 42 | match err { |
|
56 |
RevlogError::IoError(err) => CatRevError |
|
|
43 | RevlogError::IoError(err) => CatRevError::IoError(err), | |
|
57 | 44 | RevlogError::UnsuportedVersion(version) => { |
|
58 |
CatRevError |
|
|
45 | CatRevError::UnsuportedRevlogVersion(version) | |
|
59 | 46 | } |
|
60 |
RevlogError::InvalidRevision => CatRevError |
|
|
61 |
RevlogError::AmbiguousPrefix => CatRevError |
|
|
62 |
RevlogError::Corrupted => CatRevError |
|
|
47 | RevlogError::InvalidRevision => CatRevError::InvalidRevision, | |
|
48 | RevlogError::AmbiguousPrefix => CatRevError::AmbiguousPrefix, | |
|
49 | RevlogError::Corrupted => CatRevError::CorruptedRevlog, | |
|
63 | 50 | RevlogError::UnknowDataFormat(format) => { |
|
64 |
CatRevError |
|
|
51 | CatRevError::UnknowRevlogDataFormat(format) | |
|
65 | 52 | } |
|
66 | 53 | } |
|
67 | .into() | |
|
68 | 54 | } |
|
69 | 55 | } |
|
70 | 56 | |
@@ -83,7 +69,7 b' pub fn cat(' | |||
|
83 | 69 | let manifest = Manifest::open(repo)?; |
|
84 | 70 | let changelog_entry = changelog.get_rev(rev)?; |
|
85 | 71 | let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?) |
|
86 |
.map_err(|_| CatRevError |
|
|
72 | .map_err(|_| CatRevError::CorruptedRevlog)?; | |
|
87 | 73 | let manifest_entry = manifest.get_node(manifest_node.into())?; |
|
88 | 74 | let mut bytes = vec![]; |
|
89 | 75 | |
@@ -96,7 +82,7 b' pub fn cat(' | |||
|
96 | 82 | let file_log = |
|
97 | 83 | Revlog::open(repo, &index_path, Some(&data_path))?; |
|
98 | 84 | let file_node = Node::from_hex(node_bytes) |
|
99 |
.map_err(|_| CatRevError |
|
|
85 | .map_err(|_| CatRevError::CorruptedRevlog)?; | |
|
100 | 86 | let file_rev = file_log.get_node_rev(file_node.into())?; |
|
101 | 87 | let data = file_log.get_rev_data(file_rev)?; |
|
102 | 88 | if data.starts_with(&METADATA_DELIMITER) { |
@@ -15,9 +15,9 b' pub enum DebugDataKind {' | |||
|
15 | 15 | Manifest, |
|
16 | 16 | } |
|
17 | 17 | |
|
18 | /// Kind of error encountered by DebugData | |
|
18 | /// Error type for `debug_data` | |
|
19 | 19 | #[derive(Debug)] |
|
20 |
pub enum DebugDataError |
|
|
20 | pub enum DebugDataError { | |
|
21 | 21 | /// Error when reading a `revlog` file. |
|
22 | 22 | IoError(std::io::Error), |
|
23 | 23 | /// The revision has not been found. |
@@ -32,45 +32,26 b' pub enum DebugDataErrorKind {' | |||
|
32 | 32 | UnknowRevlogDataFormat(u8), |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | /// A DebugData error | |
|
36 | #[derive(Debug)] | |
|
37 | pub struct DebugDataError { | |
|
38 | /// Kind of error encountered by DebugData | |
|
39 | pub kind: DebugDataErrorKind, | |
|
40 | } | |
|
41 | ||
|
42 | impl From<DebugDataErrorKind> for DebugDataError { | |
|
43 | fn from(kind: DebugDataErrorKind) -> Self { | |
|
44 | DebugDataError { kind } | |
|
45 | } | |
|
46 | } | |
|
47 | ||
|
48 | 35 | impl From<std::io::Error> for DebugDataError { |
|
49 | 36 | fn from(err: std::io::Error) -> Self { |
|
50 |
|
|
|
51 | DebugDataError { kind } | |
|
37 | DebugDataError::IoError(err) | |
|
52 | 38 | } |
|
53 | 39 | } |
|
54 | 40 | |
|
55 | 41 | impl From<RevlogError> for DebugDataError { |
|
56 | 42 | fn from(err: RevlogError) -> Self { |
|
57 | 43 | match err { |
|
58 |
RevlogError::IoError(err) => DebugDataError |
|
|
44 | RevlogError::IoError(err) => DebugDataError::IoError(err), | |
|
59 | 45 | RevlogError::UnsuportedVersion(version) => { |
|
60 |
DebugDataError |
|
|
61 | } | |
|
62 | RevlogError::InvalidRevision => { | |
|
63 | DebugDataErrorKind::InvalidRevision | |
|
46 | DebugDataError::UnsuportedRevlogVersion(version) | |
|
64 | 47 | } |
|
65 | RevlogError::AmbiguousPrefix => { | |
|
66 | DebugDataErrorKind::AmbiguousPrefix | |
|
67 | } | |
|
68 | RevlogError::Corrupted => DebugDataErrorKind::CorruptedRevlog, | |
|
48 | RevlogError::InvalidRevision => DebugDataError::InvalidRevision, | |
|
49 | RevlogError::AmbiguousPrefix => DebugDataError::AmbiguousPrefix, | |
|
50 | RevlogError::Corrupted => DebugDataError::CorruptedRevlog, | |
|
69 | 51 | RevlogError::UnknowDataFormat(format) => { |
|
70 |
DebugDataError |
|
|
52 | DebugDataError::UnknowRevlogDataFormat(format) | |
|
71 | 53 | } |
|
72 | 54 | } |
|
73 | .into() | |
|
74 | 55 | } |
|
75 | 56 | } |
|
76 | 57 |
@@ -1,9 +1,8 b'' | |||
|
1 | use std::fmt; | |
|
2 | 1 |
|
|
3 | 2 | |
|
4 | /// Kind of error encoutered by FindRoot | |
|
3 | /// Error type for `find_root` | |
|
5 | 4 | #[derive(Debug)] |
|
6 |
pub enum FindRootError |
|
|
5 | pub enum FindRootError { | |
|
7 | 6 | /// Root of the repository has not been found |
|
8 | 7 | /// Contains the current directory used by FindRoot |
|
9 | 8 | RootNotFound(PathBuf), |
@@ -12,28 +11,12 b' pub enum FindRootErrorKind {' | |||
|
12 | 11 | GetCurrentDirError(std::io::Error), |
|
13 | 12 | } |
|
14 | 13 | |
|
15 | /// A FindRoot error | |
|
16 | #[derive(Debug)] | |
|
17 | pub struct FindRootError { | |
|
18 | /// Kind of error encoutered by FindRoot | |
|
19 | pub kind: FindRootErrorKind, | |
|
20 | } | |
|
21 | ||
|
22 | impl std::error::Error for FindRootError {} | |
|
23 | ||
|
24 | impl fmt::Display for FindRootError { | |
|
25 | fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
|
26 | unimplemented!() | |
|
27 | } | |
|
28 | } | |
|
29 | ||
|
30 | 14 | /// Find the root of the repository |
|
31 | 15 | /// by searching for a .hg directory in the processβ current directory and its |
|
32 | 16 | /// ancestors |
|
33 | 17 | pub fn find_root() -> Result<PathBuf, FindRootError> { |
|
34 |
let current_dir = std::env::current_dir() |
|
|
35 |
|
|
|
36 | })?; | |
|
18 | let current_dir = std::env::current_dir() | |
|
19 | .map_err(|e| FindRootError::GetCurrentDirError(e))?; | |
|
37 | 20 | Ok(find_root_from_path(¤t_dir)?.into()) |
|
38 | 21 | } |
|
39 | 22 | |
@@ -48,9 +31,7 b' pub fn find_root_from_path(start: &Path)' | |||
|
48 | 31 | return Ok(ancestor); |
|
49 | 32 | } |
|
50 | 33 | } |
|
51 | Err(FindRootError { | |
|
52 | kind: FindRootErrorKind::RootNotFound(start.into()), | |
|
53 | }) | |
|
34 | Err(FindRootError::RootNotFound(start.into())) | |
|
54 | 35 | } |
|
55 | 36 | |
|
56 | 37 | #[cfg(test)] |
@@ -68,10 +49,8 b' mod tests {' | |||
|
68 | 49 | |
|
69 | 50 | // TODO do something better |
|
70 | 51 | assert!(match err { |
|
71 | FindRootError { kind } => match kind { | |
|
72 | FindRootErrorKind::RootNotFound(p) => p == path.to_path_buf(), | |
|
52 | FindRootError::RootNotFound(p) => p == path.to_path_buf(), | |
|
73 | 53 |
|
|
74 | }, | |
|
75 | 54 | }) |
|
76 | 55 | } |
|
77 | 56 |
@@ -16,34 +16,18 b' use crate::{DirstateParseError, EntrySta' | |||
|
16 | 16 | use rayon::prelude::*; |
|
17 | 17 | use std::convert::From; |
|
18 | 18 | |
|
19 | /// Kind of error encountered by `ListDirstateTrackedFiles` | |
|
19 | /// Error type for `Dirstate` methods | |
|
20 | 20 | #[derive(Debug)] |
|
21 |
pub enum ListDirstateTrackedFilesError |
|
|
21 | pub enum ListDirstateTrackedFilesError { | |
|
22 | 22 | /// Error when reading the `dirstate` file |
|
23 | 23 | IoError(std::io::Error), |
|
24 | 24 | /// Error when parsing the `dirstate` file |
|
25 | 25 | ParseError(DirstateParseError), |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | /// A `ListDirstateTrackedFiles` error | |
|
29 | #[derive(Debug)] | |
|
30 | pub struct ListDirstateTrackedFilesError { | |
|
31 | /// Kind of error encountered by `ListDirstateTrackedFiles` | |
|
32 | pub kind: ListDirstateTrackedFilesErrorKind, | |
|
33 | } | |
|
34 | ||
|
35 | impl From<ListDirstateTrackedFilesErrorKind> | |
|
36 | for ListDirstateTrackedFilesError | |
|
37 | { | |
|
38 | fn from(kind: ListDirstateTrackedFilesErrorKind) -> Self { | |
|
39 | ListDirstateTrackedFilesError { kind } | |
|
40 | } | |
|
41 | } | |
|
42 | ||
|
43 | 28 | impl From<std::io::Error> for ListDirstateTrackedFilesError { |
|
44 | 29 | fn from(err: std::io::Error) -> Self { |
|
45 |
|
|
|
46 | ListDirstateTrackedFilesError { kind } | |
|
30 | ListDirstateTrackedFilesError::IoError(err) | |
|
47 | 31 | } |
|
48 | 32 | } |
|
49 | 33 | |
@@ -64,7 +48,7 b' impl Dirstate {' | |||
|
64 | 48 | &self, |
|
65 | 49 | ) -> Result<Vec<&HgPath>, ListDirstateTrackedFilesError> { |
|
66 | 50 | let (_, entries, _) = parse_dirstate(&self.content) |
|
67 |
.map_err(ListDirstateTrackedFilesError |
|
|
51 | .map_err(ListDirstateTrackedFilesError::ParseError)?; | |
|
68 | 52 | let mut files: Vec<&HgPath> = entries |
|
69 | 53 | .into_iter() |
|
70 | 54 | .filter_map(|(path, entry)| match entry.state { |
@@ -77,9 +61,9 b' impl Dirstate {' | |||
|
77 | 61 | } |
|
78 | 62 | } |
|
79 | 63 | |
|
80 |
/// |
|
|
64 | /// Error type `list_rev_tracked_files` | |
|
81 | 65 | #[derive(Debug)] |
|
82 |
pub enum ListRevTrackedFilesError |
|
|
66 | pub enum ListRevTrackedFilesError { | |
|
83 | 67 | /// Error when reading a `revlog` file. |
|
84 | 68 | IoError(std::io::Error), |
|
85 | 69 | /// The revision has not been found. |
@@ -94,42 +78,28 b' pub enum ListRevTrackedFilesErrorKind {' | |||
|
94 | 78 | UnknowRevlogDataFormat(u8), |
|
95 | 79 | } |
|
96 | 80 | |
|
97 | /// A `ListRevTrackedFiles` error | |
|
98 | #[derive(Debug)] | |
|
99 | pub struct ListRevTrackedFilesError { | |
|
100 | /// Kind of error encountered by `ListRevTrackedFiles` | |
|
101 | pub kind: ListRevTrackedFilesErrorKind, | |
|
102 | } | |
|
103 | ||
|
104 | impl From<ListRevTrackedFilesErrorKind> for ListRevTrackedFilesError { | |
|
105 | fn from(kind: ListRevTrackedFilesErrorKind) -> Self { | |
|
106 | ListRevTrackedFilesError { kind } | |
|
107 | } | |
|
108 | } | |
|
109 | ||
|
110 | 81 | impl From<RevlogError> for ListRevTrackedFilesError { |
|
111 | 82 | fn from(err: RevlogError) -> Self { |
|
112 | 83 | match err { |
|
113 | 84 | RevlogError::IoError(err) => { |
|
114 |
ListRevTrackedFilesError |
|
|
85 | ListRevTrackedFilesError::IoError(err) | |
|
115 | 86 | } |
|
116 | 87 | RevlogError::UnsuportedVersion(version) => { |
|
117 |
ListRevTrackedFilesError |
|
|
88 | ListRevTrackedFilesError::UnsuportedRevlogVersion(version) | |
|
118 | 89 | } |
|
119 | 90 | RevlogError::InvalidRevision => { |
|
120 |
ListRevTrackedFilesError |
|
|
91 | ListRevTrackedFilesError::InvalidRevision | |
|
121 | 92 | } |
|
122 | 93 | RevlogError::AmbiguousPrefix => { |
|
123 |
ListRevTrackedFilesError |
|
|
94 | ListRevTrackedFilesError::AmbiguousPrefix | |
|
124 | 95 | } |
|
125 | 96 | RevlogError::Corrupted => { |
|
126 |
ListRevTrackedFilesError |
|
|
97 | ListRevTrackedFilesError::CorruptedRevlog | |
|
127 | 98 | } |
|
128 | 99 | RevlogError::UnknowDataFormat(format) => { |
|
129 |
ListRevTrackedFilesError |
|
|
100 | ListRevTrackedFilesError::UnknowRevlogDataFormat(format) | |
|
130 | 101 | } |
|
131 | 102 | } |
|
132 | .into() | |
|
133 | 103 | } |
|
134 | 104 | } |
|
135 | 105 | |
@@ -143,7 +113,7 b' pub fn list_rev_tracked_files(' | |||
|
143 | 113 | let manifest = Manifest::open(repo)?; |
|
144 | 114 | let changelog_entry = changelog.get_rev(rev)?; |
|
145 | 115 | let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?) |
|
146 |
.or(Err(ListRevTrackedFilesError |
|
|
116 | .or(Err(ListRevTrackedFilesError::CorruptedRevlog))?; | |
|
147 | 117 | let manifest_entry = manifest.get_node(manifest_node.into())?; |
|
148 | 118 | Ok(FilesForRev(manifest_entry)) |
|
149 | 119 | } |
@@ -7,17 +7,10 b' mod debugdata;' | |||
|
7 | 7 | mod dirstate_status; |
|
8 | 8 | mod find_root; |
|
9 | 9 | mod list_tracked_files; |
|
10 |
pub use cat::{cat, CatRevError |
|
|
11 | pub use debugdata::{ | |
|
12 | debug_data, DebugDataError, DebugDataErrorKind, DebugDataKind, | |
|
13 | }; | |
|
14 | pub use find_root::{ | |
|
15 | find_root, find_root_from_path, FindRootError, FindRootErrorKind, | |
|
16 | }; | |
|
10 | pub use cat::{cat, CatRevError}; | |
|
11 | pub use debugdata::{debug_data, DebugDataError, DebugDataKind}; | |
|
12 | pub use find_root::{find_root, find_root_from_path, FindRootError}; | |
|
17 | 13 | pub use list_tracked_files::{ |
|
18 | 14 | list_rev_tracked_files, FilesForRev, ListRevTrackedFilesError, |
|
19 | ListRevTrackedFilesErrorKind, | |
|
20 | 15 | }; |
|
21 | pub use list_tracked_files::{ | |
|
22 | Dirstate, ListDirstateTrackedFilesError, ListDirstateTrackedFilesErrorKind, | |
|
23 | }; | |
|
16 | pub use list_tracked_files::{Dirstate, ListDirstateTrackedFilesError}; |
@@ -1,8 +1,8 b'' | |||
|
1 | 1 | use crate::commands::Command; |
|
2 |
use crate::error:: |
|
|
2 | use crate::error::CommandError; | |
|
3 | 3 | use crate::ui::utf8_to_local; |
|
4 | 4 | use crate::ui::Ui; |
|
5 |
use hg::operations::{cat, CatRevError |
|
|
5 | use hg::operations::{cat, CatRevError}; | |
|
6 | 6 | use hg::repo::Repo; |
|
7 | 7 | use hg::utils::hg_path::HgPathBuf; |
|
8 | 8 | use micro_timer::timed; |
@@ -34,16 +34,16 b" impl<'a> Command for CatCommand<'a> {" | |||
|
34 | 34 | let repo = Repo::find()?; |
|
35 | 35 | repo.check_requirements()?; |
|
36 | 36 | let cwd = std::env::current_dir() |
|
37 |
.or_else(|e| Err(CommandError |
|
|
37 | .or_else(|e| Err(CommandError::CurrentDirNotFound(e)))?; | |
|
38 | 38 | |
|
39 | 39 | let mut files = vec![]; |
|
40 | 40 | for file in self.files.iter() { |
|
41 | 41 | let normalized = cwd.join(&file); |
|
42 | 42 | let stripped = normalized |
|
43 | 43 | .strip_prefix(&repo.working_directory_path()) |
|
44 |
.or(Err(CommandError |
|
|
44 | .or(Err(CommandError::Abort(None)))?; | |
|
45 | 45 | let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) |
|
46 |
.or(Err(CommandError |
|
|
46 | .or(Err(CommandError::Abort(None)))?; | |
|
47 | 47 | files.push(hg_file); |
|
48 | 48 | } |
|
49 | 49 | |
@@ -53,34 +53,33 b" impl<'a> Command for CatCommand<'a> {" | |||
|
53 | 53 | .map_err(|e| map_rev_error(rev, e))?; |
|
54 | 54 | self.display(ui, &data) |
|
55 | 55 | } |
|
56 |
None => Err(CommandError |
|
|
56 | None => Err(CommandError::Unimplemented.into()), | |
|
57 | 57 | } |
|
58 | 58 | } |
|
59 | 59 | } |
|
60 | 60 | |
|
61 |
/// Convert `CatRevError |
|
|
61 | /// Convert `CatRevError` to `CommandError` | |
|
62 | 62 | fn map_rev_error(rev: &str, err: CatRevError) -> CommandError { |
|
63 |
|
|
|
64 | kind: match err.kind { | |
|
65 | CatRevErrorKind::IoError(err) => CommandErrorKind::Abort(Some( | |
|
63 | match err { | |
|
64 | CatRevError::IoError(err) => CommandError::Abort(Some( | |
|
66 | 65 |
|
|
67 | 66 |
|
|
68 |
|
|
|
67 | CatRevError::InvalidRevision => CommandError::Abort(Some( | |
|
69 | 68 |
|
|
70 | 69 |
|
|
71 | 70 |
|
|
72 | 71 |
|
|
73 | 72 |
|
|
74 | 73 |
|
|
75 |
|
|
|
74 | CatRevError::AmbiguousPrefix => CommandError::Abort(Some( | |
|
76 | 75 |
|
|
77 | 76 |
|
|
78 | 77 |
|
|
79 | 78 |
|
|
80 | 79 |
|
|
81 | 80 |
|
|
82 |
|
|
|
83 |
|
|
|
81 | CatRevError::UnsuportedRevlogVersion(version) => { | |
|
82 | CommandError::Abort(Some( | |
|
84 | 83 |
|
|
85 | 84 |
|
|
86 | 85 |
|
@@ -88,11 +87,11 b' fn map_rev_error(rev: &str, err: CatRevE' | |||
|
88 | 87 |
|
|
89 | 88 |
|
|
90 | 89 |
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
90 | CatRevError::CorruptedRevlog => { | |
|
91 | CommandError::Abort(Some("abort: corrupted revlog\n".into())) | |
|
92 | } | |
|
93 | CatRevError::UnknowRevlogDataFormat(format) => { | |
|
94 | CommandError::Abort(Some( | |
|
96 | 95 |
|
|
97 | 96 |
|
|
98 | 97 |
|
@@ -100,6 +99,5 b' fn map_rev_error(rev: &str, err: CatRevE' | |||
|
100 | 99 |
|
|
101 | 100 |
|
|
102 | 101 |
|
|
103 | }, | |
|
104 | 102 | } |
|
105 | 103 | } |
@@ -1,10 +1,8 b'' | |||
|
1 | 1 | use crate::commands::Command; |
|
2 |
use crate::error:: |
|
|
2 | use crate::error::CommandError; | |
|
3 | 3 | use crate::ui::utf8_to_local; |
|
4 | 4 | use crate::ui::Ui; |
|
5 | use hg::operations::{ | |
|
6 | debug_data, DebugDataError, DebugDataErrorKind, DebugDataKind, | |
|
7 | }; | |
|
5 | use hg::operations::{debug_data, DebugDataError, DebugDataKind}; | |
|
8 | 6 | use hg::repo::Repo; |
|
9 | 7 | use micro_timer::timed; |
|
10 | 8 | |
@@ -40,52 +38,44 b" impl<'a> Command for DebugDataCommand<'a" | |||
|
40 | 38 | |
|
41 | 39 | /// Convert operation errors to command errors |
|
42 | 40 | fn to_command_error(rev: &str, err: DebugDataError) -> CommandError { |
|
43 |
match err |
|
|
44 |
DebugDataError |
|
|
45 | kind: CommandErrorKind::Abort(Some( | |
|
41 | match err { | |
|
42 | DebugDataError::IoError(err) => CommandError::Abort(Some( | |
|
46 | 43 |
|
|
47 | 44 |
|
|
48 | }, | |
|
49 | DebugDataErrorKind::InvalidRevision => CommandError { | |
|
50 | kind: CommandErrorKind::Abort(Some( | |
|
45 | DebugDataError::InvalidRevision => CommandError::Abort(Some( | |
|
51 | 46 |
|
|
52 | 47 |
|
|
53 | 48 |
|
|
54 | 49 |
|
|
55 | 50 |
|
|
56 | 51 |
|
|
57 | }, | |
|
58 | DebugDataErrorKind::AmbiguousPrefix => CommandError { | |
|
59 | kind: CommandErrorKind::Abort(Some( | |
|
52 | DebugDataError::AmbiguousPrefix => CommandError::Abort(Some( | |
|
60 | 53 |
|
|
61 | 54 |
|
|
62 | 55 |
|
|
63 | 56 |
|
|
64 | 57 |
|
|
65 | 58 |
|
|
66 | }, | |
|
67 | DebugDataErrorKind::UnsuportedRevlogVersion(version) => CommandError { | |
|
68 | kind: CommandErrorKind::Abort(Some( | |
|
59 | DebugDataError::UnsuportedRevlogVersion(version) => { | |
|
60 | CommandError::Abort(Some( | |
|
69 | 61 | utf8_to_local(&format!( |
|
70 | 62 | "abort: unsupported revlog version {}\n", |
|
71 | 63 | version |
|
72 | 64 | )) |
|
73 | 65 | .into(), |
|
74 |
)) |
|
|
75 |
} |
|
|
76 |
DebugDataError |
|
|
77 |
|
|
|
78 | "abort: corrupted revlog\n".into(), | |
|
79 | )), | |
|
80 | }, | |
|
81 | DebugDataErrorKind::UnknowRevlogDataFormat(format) => CommandError { | |
|
82 | kind: CommandErrorKind::Abort(Some( | |
|
66 | )) | |
|
67 | } | |
|
68 | DebugDataError::CorruptedRevlog => { | |
|
69 | CommandError::Abort(Some("abort: corrupted revlog\n".into())) | |
|
70 | } | |
|
71 | DebugDataError::UnknowRevlogDataFormat(format) => { | |
|
72 | CommandError::Abort(Some( | |
|
83 | 73 | utf8_to_local(&format!( |
|
84 | 74 | "abort: unknow revlog dataformat {:?}\n", |
|
85 | 75 | format |
|
86 | 76 | )) |
|
87 | 77 | .into(), |
|
88 |
)) |
|
|
89 | }, | |
|
78 | )) | |
|
90 | 79 | } |
|
91 | 80 | } |
|
81 | } |
@@ -1,14 +1,9 b'' | |||
|
1 | 1 | use crate::commands::Command; |
|
2 |
use crate::error:: |
|
|
2 | use crate::error::CommandError; | |
|
3 | 3 | use crate::ui::utf8_to_local; |
|
4 | 4 | use crate::ui::Ui; |
|
5 | use hg::operations::{ | |
|
6 | list_rev_tracked_files, ListRevTrackedFilesError, | |
|
7 | ListRevTrackedFilesErrorKind, | |
|
8 | }; | |
|
9 | use hg::operations::{ | |
|
10 | Dirstate, ListDirstateTrackedFilesError, ListDirstateTrackedFilesErrorKind, | |
|
11 | }; | |
|
5 | use hg::operations::{list_rev_tracked_files, ListRevTrackedFilesError}; | |
|
6 | use hg::operations::{Dirstate, ListDirstateTrackedFilesError}; | |
|
12 | 7 | use hg::repo::Repo; |
|
13 | 8 | use hg::utils::files::{get_bytes_from_path, relativize_path}; |
|
14 | 9 | use hg::utils::hg_path::{HgPath, HgPathBuf}; |
@@ -35,7 +30,7 b" impl<'a> FilesCommand<'a> {" | |||
|
35 | 30 | files: impl IntoIterator<Item = &'a HgPath>, |
|
36 | 31 | ) -> Result<(), CommandError> { |
|
37 | 32 | let cwd = std::env::current_dir() |
|
38 |
.or_else(|e| Err(CommandError |
|
|
33 | .or_else(|e| Err(CommandError::CurrentDirNotFound(e)))?; | |
|
39 | 34 | let rooted_cwd = cwd |
|
40 | 35 | .strip_prefix(repo.working_directory_path()) |
|
41 | 36 | .expect("cwd was already checked within the repository"); |
@@ -68,17 +63,14 b" impl<'a> Command for FilesCommand<'a> {" | |||
|
68 | 63 | } |
|
69 | 64 | } |
|
70 | 65 | |
|
71 |
/// Convert `ListRevTrackedFilesError |
|
|
66 | /// Convert `ListRevTrackedFilesError` to `CommandError` | |
|
72 | 67 | fn map_rev_error(rev: &str, err: ListRevTrackedFilesError) -> CommandError { |
|
73 |
|
|
|
74 | kind: match err.kind { | |
|
75 | ListRevTrackedFilesErrorKind::IoError(err) => { | |
|
76 | CommandErrorKind::Abort(Some( | |
|
68 | match err { | |
|
69 | ListRevTrackedFilesError::IoError(err) => CommandError::Abort(Some( | |
|
77 | 70 |
|
|
78 |
|
|
|
79 | } | |
|
80 | ListRevTrackedFilesErrorKind::InvalidRevision => { | |
|
81 | CommandErrorKind::Abort(Some( | |
|
71 | )), | |
|
72 | ListRevTrackedFilesError::InvalidRevision => { | |
|
73 | CommandError::Abort(Some( | |
|
82 | 74 |
|
|
83 | 75 |
|
|
84 | 76 |
|
@@ -86,8 +78,8 b' fn map_rev_error(rev: &str, err: ListRev' | |||
|
86 | 78 |
|
|
87 | 79 |
|
|
88 | 80 |
|
|
89 |
|
|
|
90 |
|
|
|
81 | ListRevTrackedFilesError::AmbiguousPrefix => { | |
|
82 | CommandError::Abort(Some( | |
|
91 | 83 |
|
|
92 | 84 |
|
|
93 | 85 |
|
@@ -95,8 +87,8 b' fn map_rev_error(rev: &str, err: ListRev' | |||
|
95 | 87 |
|
|
96 | 88 |
|
|
97 | 89 |
|
|
98 |
|
|
|
99 |
|
|
|
90 | ListRevTrackedFilesError::UnsuportedRevlogVersion(version) => { | |
|
91 | CommandError::Abort(Some( | |
|
100 | 92 |
|
|
101 | 93 |
|
|
102 | 94 |
|
@@ -104,13 +96,11 b' fn map_rev_error(rev: &str, err: ListRev' | |||
|
104 | 96 |
|
|
105 | 97 |
|
|
106 | 98 |
|
|
107 |
|
|
|
108 |
|
|
|
109 | "abort: corrupted revlog\n".into(), | |
|
110 | )) | |
|
99 | ListRevTrackedFilesError::CorruptedRevlog => { | |
|
100 | CommandError::Abort(Some("abort: corrupted revlog\n".into())) | |
|
111 | 101 |
|
|
112 |
|
|
|
113 |
|
|
|
102 | ListRevTrackedFilesError::UnknowRevlogDataFormat(format) => { | |
|
103 | CommandError::Abort(Some( | |
|
114 | 104 |
|
|
115 | 105 |
|
|
116 | 106 |
|
@@ -118,25 +108,20 b' fn map_rev_error(rev: &str, err: ListRev' | |||
|
118 | 108 |
|
|
119 | 109 |
|
|
120 | 110 |
|
|
121 | }, | |
|
122 | 111 | } |
|
123 | 112 | } |
|
124 | 113 | |
|
125 | 114 | /// Convert `ListDirstateTrackedFilesError` to `CommandError` |
|
126 | 115 | fn map_dirstate_error(err: ListDirstateTrackedFilesError) -> CommandError { |
|
127 |
|
|
|
128 | kind: match err.kind { | |
|
129 | ListDirstateTrackedFilesErrorKind::IoError(err) => { | |
|
130 | CommandErrorKind::Abort(Some( | |
|
131 | utf8_to_local(&format!("abort: {}\n", err)).into(), | |
|
132 | )) | |
|
133 | } | |
|
134 | ListDirstateTrackedFilesErrorKind::ParseError(_) => { | |
|
135 | CommandErrorKind::Abort(Some( | |
|
116 | match err { | |
|
117 | ListDirstateTrackedFilesError::IoError(err) => CommandError::Abort( | |
|
118 | Some(utf8_to_local(&format!("abort: {}\n", err)).into()), | |
|
119 | ), | |
|
120 | ListDirstateTrackedFilesError::ParseError(_) => { | |
|
121 | CommandError::Abort(Some( | |
|
136 | 122 |
|
|
137 | 123 |
|
|
138 | 124 |
|
|
139 | 125 |
|
|
140 | }, | |
|
141 | 126 | } |
|
142 | 127 | } |
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | use crate::exitcode; |
|
2 | 2 | use crate::ui::UiError; |
|
3 | 3 | use format_bytes::format_bytes; |
|
4 |
use hg::operations:: |
|
|
4 | use hg::operations::FindRootError; | |
|
5 | 5 | use hg::requirements::RequirementsError; |
|
6 | 6 | use hg::utils::files::get_bytes_from_path; |
|
7 | 7 | use std::convert::From; |
@@ -9,7 +9,7 b' use std::path::PathBuf;' | |||
|
9 | 9 | |
|
10 | 10 | /// The kind of command error |
|
11 | 11 | #[derive(Debug)] |
|
12 |
pub enum CommandError |
|
|
12 | pub enum CommandError { | |
|
13 | 13 | /// The root of the repository cannot be found |
|
14 | 14 | RootNotFound(PathBuf), |
|
15 | 15 | /// The current directory cannot be found |
@@ -26,99 +26,76 b' pub enum CommandErrorKind {' | |||
|
26 | 26 | Unimplemented, |
|
27 | 27 | } |
|
28 | 28 | |
|
29 |
impl CommandError |
|
|
29 | impl CommandError { | |
|
30 | 30 | pub fn get_exit_code(&self) -> exitcode::ExitCode { |
|
31 | 31 | match self { |
|
32 |
CommandError |
|
|
33 |
CommandError |
|
|
34 |
CommandError |
|
|
32 | CommandError::RootNotFound(_) => exitcode::ABORT, | |
|
33 | CommandError::CurrentDirNotFound(_) => exitcode::ABORT, | |
|
34 | CommandError::RequirementsError( | |
|
35 | 35 | RequirementsError::Unsupported { .. }, |
|
36 | 36 | ) => exitcode::UNIMPLEMENTED_COMMAND, |
|
37 |
CommandError |
|
|
38 |
CommandError |
|
|
39 |
CommandError |
|
|
40 |
CommandError |
|
|
41 |
CommandError |
|
|
37 | CommandError::RequirementsError(_) => exitcode::ABORT, | |
|
38 | CommandError::StdoutError => exitcode::ABORT, | |
|
39 | CommandError::StderrError => exitcode::ABORT, | |
|
40 | CommandError::Abort(_) => exitcode::ABORT, | |
|
41 | CommandError::Unimplemented => exitcode::UNIMPLEMENTED_COMMAND, | |
|
42 | 42 | } |
|
43 | 43 | } |
|
44 | 44 | |
|
45 |
/// Return the message corresponding to the error |
|
|
45 | /// Return the message corresponding to the error if any | |
|
46 | 46 | pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> { |
|
47 | 47 | match self { |
|
48 |
CommandError |
|
|
48 | CommandError::RootNotFound(path) => { | |
|
49 | 49 | let bytes = get_bytes_from_path(path); |
|
50 | 50 | Some(format_bytes!( |
|
51 | 51 | b"abort: no repository found in '{}' (.hg not found)!\n", |
|
52 | 52 | bytes.as_slice() |
|
53 | 53 | )) |
|
54 | 54 | } |
|
55 |
CommandError |
|
|
55 | CommandError::CurrentDirNotFound(e) => Some(format_bytes!( | |
|
56 | 56 | b"abort: error getting current working directory: {}\n", |
|
57 | 57 | e.to_string().as_bytes(), |
|
58 | 58 | )), |
|
59 |
CommandError |
|
|
60 | RequirementsError::Corrupted, | |
|
61 | ) => Some( | |
|
59 | CommandError::RequirementsError(RequirementsError::Corrupted) => { | |
|
60 | Some( | |
|
62 | 61 | "abort: .hg/requires is corrupted\n".as_bytes().to_owned(), |
|
63 |
) |
|
|
64 | CommandErrorKind::Abort(message) => message.to_owned(), | |
|
62 | ) | |
|
63 | } | |
|
64 | CommandError::Abort(message) => message.to_owned(), | |
|
65 | 65 | _ => None, |
|
66 | 66 | } |
|
67 | 67 | } |
|
68 | } | |
|
69 | 68 | |
|
70 | /// The error type for the Command trait | |
|
71 | #[derive(Debug)] | |
|
72 | pub struct CommandError { | |
|
73 | pub kind: CommandErrorKind, | |
|
74 | } | |
|
75 | ||
|
76 | impl CommandError { | |
|
77 | 69 | /// Exist the process with the corresponding exit code. |
|
78 | 70 | pub fn exit(&self) { |
|
79 |
std::process::exit(self. |
|
|
80 | } | |
|
81 | ||
|
82 | /// Return the message corresponding to the command error if any | |
|
83 | pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> { | |
|
84 | self.kind.get_error_message_bytes() | |
|
85 | } | |
|
86 | } | |
|
87 | ||
|
88 | impl From<CommandErrorKind> for CommandError { | |
|
89 | fn from(kind: CommandErrorKind) -> Self { | |
|
90 | CommandError { kind } | |
|
71 | std::process::exit(self.get_exit_code()) | |
|
91 | 72 | } |
|
92 | 73 | } |
|
93 | 74 | |
|
94 | 75 | impl From<UiError> for CommandError { |
|
95 | 76 | fn from(error: UiError) -> Self { |
|
96 |
|
|
|
97 | kind: match error { | |
|
98 |
|
|
|
99 | UiError::StderrError(_) => CommandErrorKind::StderrError, | |
|
100 | }, | |
|
77 | match error { | |
|
78 | UiError::StdoutError(_) => CommandError::StdoutError, | |
|
79 | UiError::StderrError(_) => CommandError::StderrError, | |
|
101 | 80 | } |
|
102 | 81 | } |
|
103 | 82 | } |
|
104 | 83 | |
|
105 | 84 | impl From<FindRootError> for CommandError { |
|
106 | 85 | fn from(err: FindRootError) -> Self { |
|
107 |
match err |
|
|
108 |
FindRootError |
|
|
109 |
|
|
|
110 |
} |
|
|
111 |
FindRootError |
|
|
112 |
|
|
|
113 |
} |
|
|
86 | match err { | |
|
87 | FindRootError::RootNotFound(path) => { | |
|
88 | CommandError::RootNotFound(path) | |
|
89 | } | |
|
90 | FindRootError::GetCurrentDirError(e) => { | |
|
91 | CommandError::CurrentDirNotFound(e) | |
|
92 | } | |
|
114 | 93 | } |
|
115 | 94 | } |
|
116 | 95 | } |
|
117 | 96 | |
|
118 | 97 | impl From<RequirementsError> for CommandError { |
|
119 | 98 | fn from(err: RequirementsError) -> Self { |
|
120 |
CommandError |
|
|
121 | kind: CommandErrorKind::RequirementsError(err), | |
|
99 | CommandError::RequirementsError(err) | |
|
122 | 100 |
|
|
123 | 101 | } |
|
124 | } |
General Comments 0
You need to be logged in to leave comments.
Login now