##// END OF EJS Templates
rust: remove three enums that were identical to `RevlogError`...
Simon Sapin -
r47166:b274aa2f default
parent child Browse files
Show More
@@ -5,7 +5,6 b''
5 // This software may be used and distributed according to the terms of the
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 use std::convert::From;
9 use std::path::PathBuf;
8 use std::path::PathBuf;
10
9
11 use crate::repo::Repo;
10 use crate::repo::Repo;
@@ -20,40 +19,6 b' use crate::utils::hg_path::{HgPath, HgPa'
20
19
21 const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n'];
20 const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n'];
22
21
23 /// Error type for `cat`
24 #[derive(Debug)]
25 pub enum CatRevError {
26 /// Error when reading a `revlog` file.
27 IoError(std::io::Error),
28 /// The revision has not been found.
29 InvalidRevision,
30 /// Found more than one revision whose ID match the requested prefix
31 AmbiguousPrefix,
32 /// A `revlog` file is corrupted.
33 CorruptedRevlog,
34 /// The `revlog` format version is not supported.
35 UnsuportedRevlogVersion(u16),
36 /// The `revlog` data format is not supported.
37 UnknowRevlogDataFormat(u8),
38 }
39
40 impl From<RevlogError> for CatRevError {
41 fn from(err: RevlogError) -> Self {
42 match err {
43 RevlogError::IoError(err) => CatRevError::IoError(err),
44 RevlogError::UnsuportedVersion(version) => {
45 CatRevError::UnsuportedRevlogVersion(version)
46 }
47 RevlogError::InvalidRevision => CatRevError::InvalidRevision,
48 RevlogError::AmbiguousPrefix => CatRevError::AmbiguousPrefix,
49 RevlogError::Corrupted => CatRevError::CorruptedRevlog,
50 RevlogError::UnknowDataFormat(format) => {
51 CatRevError::UnknowRevlogDataFormat(format)
52 }
53 }
54 }
55 }
56
57 /// List files under Mercurial control at a given revision.
22 /// List files under Mercurial control at a given revision.
58 ///
23 ///
59 /// * `root`: Repository root
24 /// * `root`: Repository root
@@ -63,13 +28,13 b' pub fn cat('
63 repo: &Repo,
28 repo: &Repo,
64 revset: &str,
29 revset: &str,
65 files: &[HgPathBuf],
30 files: &[HgPathBuf],
66 ) -> Result<Vec<u8>, CatRevError> {
31 ) -> Result<Vec<u8>, RevlogError> {
67 let rev = crate::revset::resolve_single(revset, repo)?;
32 let rev = crate::revset::resolve_single(revset, repo)?;
68 let changelog = Changelog::open(repo)?;
33 let changelog = Changelog::open(repo)?;
69 let manifest = Manifest::open(repo)?;
34 let manifest = Manifest::open(repo)?;
70 let changelog_entry = changelog.get_rev(rev)?;
35 let changelog_entry = changelog.get_rev(rev)?;
71 let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?)
36 let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?)
72 .map_err(|_| CatRevError::CorruptedRevlog)?;
37 .map_err(|_| RevlogError::Corrupted)?;
73 let manifest_entry = manifest.get_node(manifest_node.into())?;
38 let manifest_entry = manifest.get_node(manifest_node.into())?;
74 let mut bytes = vec![];
39 let mut bytes = vec![];
75
40
@@ -82,7 +47,7 b' pub fn cat('
82 let file_log =
47 let file_log =
83 Revlog::open(repo, &index_path, Some(&data_path))?;
48 Revlog::open(repo, &index_path, Some(&data_path))?;
84 let file_node = Node::from_hex(node_bytes)
49 let file_node = Node::from_hex(node_bytes)
85 .map_err(|_| CatRevError::CorruptedRevlog)?;
50 .map_err(|_| RevlogError::Corrupted)?;
86 let file_rev = file_log.get_node_rev(file_node.into())?;
51 let file_rev = file_log.get_node_rev(file_node.into())?;
87 let data = file_log.get_rev_data(file_rev)?;
52 let data = file_log.get_rev_data(file_rev)?;
88 if data.starts_with(&METADATA_DELIMITER) {
53 if data.starts_with(&METADATA_DELIMITER) {
@@ -15,47 +15,12 b' pub enum DebugDataKind {'
15 Manifest,
15 Manifest,
16 }
16 }
17
17
18 /// Error type for `debug_data`
19 #[derive(Debug, derive_more::From)]
20 pub enum DebugDataError {
21 /// Error when reading a `revlog` file.
22 #[from]
23 IoError(std::io::Error),
24 /// The revision has not been found.
25 InvalidRevision,
26 /// Found more than one revision whose ID match the requested prefix
27 AmbiguousPrefix,
28 /// A `revlog` file is corrupted.
29 CorruptedRevlog,
30 /// The `revlog` format version is not supported.
31 UnsuportedRevlogVersion(u16),
32 /// The `revlog` data format is not supported.
33 UnknowRevlogDataFormat(u8),
34 }
35
36 impl From<RevlogError> for DebugDataError {
37 fn from(err: RevlogError) -> Self {
38 match err {
39 RevlogError::IoError(err) => DebugDataError::IoError(err),
40 RevlogError::UnsuportedVersion(version) => {
41 DebugDataError::UnsuportedRevlogVersion(version)
42 }
43 RevlogError::InvalidRevision => DebugDataError::InvalidRevision,
44 RevlogError::AmbiguousPrefix => DebugDataError::AmbiguousPrefix,
45 RevlogError::Corrupted => DebugDataError::CorruptedRevlog,
46 RevlogError::UnknowDataFormat(format) => {
47 DebugDataError::UnknowRevlogDataFormat(format)
48 }
49 }
50 }
51 }
52
53 /// Dump the contents data of a revision.
18 /// Dump the contents data of a revision.
54 pub fn debug_data(
19 pub fn debug_data(
55 repo: &Repo,
20 repo: &Repo,
56 revset: &str,
21 revset: &str,
57 kind: DebugDataKind,
22 kind: DebugDataKind,
58 ) -> Result<Vec<u8>, DebugDataError> {
23 ) -> Result<Vec<u8>, RevlogError> {
59 let index_file = match kind {
24 let index_file = match kind {
60 DebugDataKind::Changelog => "00changelog.i",
25 DebugDataKind::Changelog => "00changelog.i",
61 DebugDataKind::Manifest => "00manifest.i",
26 DebugDataKind::Manifest => "00manifest.i",
@@ -14,7 +14,6 b' use crate::revlog::revlog::RevlogError;'
14 use crate::utils::hg_path::HgPath;
14 use crate::utils::hg_path::HgPath;
15 use crate::{DirstateParseError, EntryState};
15 use crate::{DirstateParseError, EntryState};
16 use rayon::prelude::*;
16 use rayon::prelude::*;
17 use std::convert::From;
18
17
19 /// Error type for `Dirstate` methods
18 /// Error type for `Dirstate` methods
20 #[derive(Debug, derive_more::From)]
19 #[derive(Debug, derive_more::From)]
@@ -55,59 +54,17 b' impl Dirstate {'
55 }
54 }
56 }
55 }
57
56
58 /// Error type `list_rev_tracked_files`
59 #[derive(Debug)]
60 pub enum ListRevTrackedFilesError {
61 /// Error when reading a `revlog` file.
62 IoError(std::io::Error),
63 /// The revision has not been found.
64 InvalidRevision,
65 /// Found more than one revision whose ID match the requested prefix
66 AmbiguousPrefix,
67 /// A `revlog` file is corrupted.
68 CorruptedRevlog,
69 /// The `revlog` format version is not supported.
70 UnsuportedRevlogVersion(u16),
71 /// The `revlog` data format is not supported.
72 UnknowRevlogDataFormat(u8),
73 }
74
75 impl From<RevlogError> for ListRevTrackedFilesError {
76 fn from(err: RevlogError) -> Self {
77 match err {
78 RevlogError::IoError(err) => {
79 ListRevTrackedFilesError::IoError(err)
80 }
81 RevlogError::UnsuportedVersion(version) => {
82 ListRevTrackedFilesError::UnsuportedRevlogVersion(version)
83 }
84 RevlogError::InvalidRevision => {
85 ListRevTrackedFilesError::InvalidRevision
86 }
87 RevlogError::AmbiguousPrefix => {
88 ListRevTrackedFilesError::AmbiguousPrefix
89 }
90 RevlogError::Corrupted => {
91 ListRevTrackedFilesError::CorruptedRevlog
92 }
93 RevlogError::UnknowDataFormat(format) => {
94 ListRevTrackedFilesError::UnknowRevlogDataFormat(format)
95 }
96 }
97 }
98 }
99
100 /// List files under Mercurial control at a given revision.
57 /// List files under Mercurial control at a given revision.
101 pub fn list_rev_tracked_files(
58 pub fn list_rev_tracked_files(
102 repo: &Repo,
59 repo: &Repo,
103 revset: &str,
60 revset: &str,
104 ) -> Result<FilesForRev, ListRevTrackedFilesError> {
61 ) -> Result<FilesForRev, RevlogError> {
105 let rev = crate::revset::resolve_single(revset, repo)?;
62 let rev = crate::revset::resolve_single(revset, repo)?;
106 let changelog = Changelog::open(repo)?;
63 let changelog = Changelog::open(repo)?;
107 let manifest = Manifest::open(repo)?;
64 let manifest = Manifest::open(repo)?;
108 let changelog_entry = changelog.get_rev(rev)?;
65 let changelog_entry = changelog.get_rev(rev)?;
109 let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?)
66 let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?)
110 .or(Err(ListRevTrackedFilesError::CorruptedRevlog))?;
67 .map_err(|_| RevlogError::Corrupted)?;
111 let manifest_entry = manifest.get_node(manifest_node.into())?;
68 let manifest_entry = manifest.get_node(manifest_node.into())?;
112 Ok(FilesForRev(manifest_entry))
69 Ok(FilesForRev(manifest_entry))
113 }
70 }
@@ -7,10 +7,8 b' mod debugdata;'
7 mod dirstate_status;
7 mod dirstate_status;
8 mod find_root;
8 mod find_root;
9 mod list_tracked_files;
9 mod list_tracked_files;
10 pub use cat::{cat, CatRevError};
10 pub use cat::cat;
11 pub use debugdata::{debug_data, DebugDataError, DebugDataKind};
11 pub use debugdata::{debug_data, DebugDataKind};
12 pub use find_root::{find_root, find_root_from_path, FindRootError};
12 pub use find_root::{find_root, find_root_from_path, FindRootError};
13 pub use list_tracked_files::{
13 pub use list_tracked_files::{list_rev_tracked_files, FilesForRev};
14 list_rev_tracked_files, FilesForRev, ListRevTrackedFilesError,
15 };
16 pub use list_tracked_files::{Dirstate, ListDirstateTrackedFilesError};
14 pub use list_tracked_files::{Dirstate, ListDirstateTrackedFilesError};
@@ -2,11 +2,9 b' use crate::exitcode;'
2 use crate::ui::utf8_to_local;
2 use crate::ui::utf8_to_local;
3 use crate::ui::UiError;
3 use crate::ui::UiError;
4 use format_bytes::format_bytes;
4 use format_bytes::format_bytes;
5 use hg::operations::{
5 use hg::operations::{FindRootError, ListDirstateTrackedFilesError};
6 CatRevError, DebugDataError, FindRootError, ListDirstateTrackedFilesError,
7 ListRevTrackedFilesError,
8 };
9 use hg::requirements::RequirementsError;
6 use hg::requirements::RequirementsError;
7 use hg::revlog::revlog::RevlogError;
10 use hg::utils::files::get_bytes_from_path;
8 use hg::utils::files::get_bytes_from_path;
11 use std::convert::From;
9 use std::convert::From;
12 use std::path::PathBuf;
10 use std::path::PathBuf;
@@ -99,27 +97,27 b' impl From<FindRootError> for CommandErro'
99 }
97 }
100 }
98 }
101
99
102 impl From<(DebugDataError, &str)> for CommandError {
100 impl From<(RevlogError, &str)> for CommandError {
103 fn from((err, rev): (DebugDataError, &str)) -> CommandError {
101 fn from((err, rev): (RevlogError, &str)) -> CommandError {
104 match err {
102 match err {
105 DebugDataError::IoError(err) => CommandError::Abort(Some(
103 RevlogError::IoError(err) => CommandError::Abort(Some(
106 utf8_to_local(&format!("abort: {}\n", err)).into(),
104 utf8_to_local(&format!("abort: {}\n", err)).into(),
107 )),
105 )),
108 DebugDataError::InvalidRevision => CommandError::Abort(Some(
106 RevlogError::InvalidRevision => CommandError::Abort(Some(
109 utf8_to_local(&format!(
107 utf8_to_local(&format!(
110 "abort: invalid revision identifier{}\n",
108 "abort: invalid revision identifier {}\n",
111 rev
109 rev
112 ))
110 ))
113 .into(),
111 .into(),
114 )),
112 )),
115 DebugDataError::AmbiguousPrefix => CommandError::Abort(Some(
113 RevlogError::AmbiguousPrefix => CommandError::Abort(Some(
116 utf8_to_local(&format!(
114 utf8_to_local(&format!(
117 "abort: ambiguous revision identifier{}\n",
115 "abort: ambiguous revision identifier {}\n",
118 rev
116 rev
119 ))
117 ))
120 .into(),
118 .into(),
121 )),
119 )),
122 DebugDataError::UnsuportedRevlogVersion(version) => {
120 RevlogError::UnsuportedVersion(version) => {
123 CommandError::Abort(Some(
121 CommandError::Abort(Some(
124 utf8_to_local(&format!(
122 utf8_to_local(&format!(
125 "abort: unsupported revlog version {}\n",
123 "abort: unsupported revlog version {}\n",
@@ -128,104 +126,10 b' impl From<(DebugDataError, &str)> for Co'
128 .into(),
126 .into(),
129 ))
127 ))
130 }
128 }
131 DebugDataError::CorruptedRevlog => {
129 RevlogError::Corrupted => {
132 CommandError::Abort(Some("abort: corrupted revlog\n".into()))
130 CommandError::Abort(Some("abort: corrupted revlog\n".into()))
133 }
131 }
134 DebugDataError::UnknowRevlogDataFormat(format) => {
132 RevlogError::UnknowDataFormat(format) => {
135 CommandError::Abort(Some(
136 utf8_to_local(&format!(
137 "abort: unknow revlog dataformat {:?}\n",
138 format
139 ))
140 .into(),
141 ))
142 }
143 }
144 }
145 }
146
147 impl From<(ListRevTrackedFilesError, &str)> for CommandError {
148 fn from((err, rev): (ListRevTrackedFilesError, &str)) -> CommandError {
149 match err {
150 ListRevTrackedFilesError::IoError(err) => CommandError::Abort(
151 Some(utf8_to_local(&format!("abort: {}\n", err)).into()),
152 ),
153 ListRevTrackedFilesError::InvalidRevision => {
154 CommandError::Abort(Some(
155 utf8_to_local(&format!(
156 "abort: invalid revision identifier {}\n",
157 rev
158 ))
159 .into(),
160 ))
161 }
162 ListRevTrackedFilesError::AmbiguousPrefix => {
163 CommandError::Abort(Some(
164 utf8_to_local(&format!(
165 "abort: ambiguous revision identifier {}\n",
166 rev
167 ))
168 .into(),
169 ))
170 }
171 ListRevTrackedFilesError::UnsuportedRevlogVersion(version) => {
172 CommandError::Abort(Some(
173 utf8_to_local(&format!(
174 "abort: unsupported revlog version {}\n",
175 version
176 ))
177 .into(),
178 ))
179 }
180 ListRevTrackedFilesError::CorruptedRevlog => {
181 CommandError::Abort(Some("abort: corrupted revlog\n".into()))
182 }
183 ListRevTrackedFilesError::UnknowRevlogDataFormat(format) => {
184 CommandError::Abort(Some(
185 utf8_to_local(&format!(
186 "abort: unknow revlog dataformat {:?}\n",
187 format
188 ))
189 .into(),
190 ))
191 }
192 }
193 }
194 }
195
196 impl From<(CatRevError, &str)> for CommandError {
197 fn from((err, rev): (CatRevError, &str)) -> CommandError {
198 match err {
199 CatRevError::IoError(err) => CommandError::Abort(Some(
200 utf8_to_local(&format!("abort: {}\n", err)).into(),
201 )),
202 CatRevError::InvalidRevision => CommandError::Abort(Some(
203 utf8_to_local(&format!(
204 "abort: invalid revision identifier {}\n",
205 rev
206 ))
207 .into(),
208 )),
209 CatRevError::AmbiguousPrefix => CommandError::Abort(Some(
210 utf8_to_local(&format!(
211 "abort: ambiguous revision identifier {}\n",
212 rev
213 ))
214 .into(),
215 )),
216 CatRevError::UnsuportedRevlogVersion(version) => {
217 CommandError::Abort(Some(
218 utf8_to_local(&format!(
219 "abort: unsupported revlog version {}\n",
220 version
221 ))
222 .into(),
223 ))
224 }
225 CatRevError::CorruptedRevlog => {
226 CommandError::Abort(Some("abort: corrupted revlog\n".into()))
227 }
228 CatRevError::UnknowRevlogDataFormat(format) => {
229 CommandError::Abort(Some(
133 CommandError::Abort(Some(
230 utf8_to_local(&format!(
134 utf8_to_local(&format!(
231 "abort: unknow revlog dataformat {:?}\n",
135 "abort: unknow revlog dataformat {:?}\n",
General Comments 0
You need to be logged in to leave comments. Login now