Mercurial > public > mercurial-scm > hg
comparison rust/rhg/src/commands/files.rs @ 46434:3e2d539d0d1a
rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Use the enum directly as `FooError` instead.
Differential Revision: https://phab.mercurial-scm.org/D9874
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 26 Jan 2021 19:07:24 +0100 |
parents | 8a4914397d02 |
children | 252d1bdba33d |
comparison
equal
deleted
inserted
replaced
46433:4b381dbbf8b7 | 46434:3e2d539d0d1a |
---|---|
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::utf8_to_local; | 3 use crate::ui::utf8_to_local; |
4 use crate::ui::Ui; | 4 use crate::ui::Ui; |
5 use hg::operations::{ | 5 use hg::operations::{list_rev_tracked_files, ListRevTrackedFilesError}; |
6 list_rev_tracked_files, ListRevTrackedFilesError, | 6 use hg::operations::{Dirstate, ListDirstateTrackedFilesError}; |
7 ListRevTrackedFilesErrorKind, | |
8 }; | |
9 use hg::operations::{ | |
10 Dirstate, ListDirstateTrackedFilesError, ListDirstateTrackedFilesErrorKind, | |
11 }; | |
12 use hg::repo::Repo; | 7 use hg::repo::Repo; |
13 use hg::utils::files::{get_bytes_from_path, relativize_path}; | 8 use hg::utils::files::{get_bytes_from_path, relativize_path}; |
14 use hg::utils::hg_path::{HgPath, HgPathBuf}; | 9 use hg::utils::hg_path::{HgPath, HgPathBuf}; |
15 | 10 |
16 pub const HELP_TEXT: &str = " | 11 pub const HELP_TEXT: &str = " |
33 ui: &Ui, | 28 ui: &Ui, |
34 repo: &Repo, | 29 repo: &Repo, |
35 files: impl IntoIterator<Item = &'a HgPath>, | 30 files: impl IntoIterator<Item = &'a HgPath>, |
36 ) -> Result<(), CommandError> { | 31 ) -> Result<(), CommandError> { |
37 let cwd = std::env::current_dir() | 32 let cwd = std::env::current_dir() |
38 .or_else(|e| Err(CommandErrorKind::CurrentDirNotFound(e)))?; | 33 .or_else(|e| Err(CommandError::CurrentDirNotFound(e)))?; |
39 let rooted_cwd = cwd | 34 let rooted_cwd = cwd |
40 .strip_prefix(repo.working_directory_path()) | 35 .strip_prefix(repo.working_directory_path()) |
41 .expect("cwd was already checked within the repository"); | 36 .expect("cwd was already checked within the repository"); |
42 let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd)); | 37 let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd)); |
43 | 38 |
66 self.display_files(ui, &repo, files) | 61 self.display_files(ui, &repo, files) |
67 } | 62 } |
68 } | 63 } |
69 } | 64 } |
70 | 65 |
71 /// Convert `ListRevTrackedFilesErrorKind` to `CommandError` | 66 /// Convert `ListRevTrackedFilesError` to `CommandError` |
72 fn map_rev_error(rev: &str, err: ListRevTrackedFilesError) -> CommandError { | 67 fn map_rev_error(rev: &str, err: ListRevTrackedFilesError) -> CommandError { |
73 CommandError { | 68 match err { |
74 kind: match err.kind { | 69 ListRevTrackedFilesError::IoError(err) => CommandError::Abort(Some( |
75 ListRevTrackedFilesErrorKind::IoError(err) => { | 70 utf8_to_local(&format!("abort: {}\n", err)).into(), |
76 CommandErrorKind::Abort(Some( | 71 )), |
77 utf8_to_local(&format!("abort: {}\n", err)).into(), | 72 ListRevTrackedFilesError::InvalidRevision => { |
73 CommandError::Abort(Some( | |
74 utf8_to_local(&format!( | |
75 "abort: invalid revision identifier {}\n", | |
76 rev | |
78 )) | 77 )) |
79 } | 78 .into(), |
80 ListRevTrackedFilesErrorKind::InvalidRevision => { | 79 )) |
81 CommandErrorKind::Abort(Some( | 80 } |
82 utf8_to_local(&format!( | 81 ListRevTrackedFilesError::AmbiguousPrefix => { |
83 "abort: invalid revision identifier {}\n", | 82 CommandError::Abort(Some( |
84 rev | 83 utf8_to_local(&format!( |
85 )) | 84 "abort: ambiguous revision identifier {}\n", |
86 .into(), | 85 rev |
87 )) | 86 )) |
88 } | 87 .into(), |
89 ListRevTrackedFilesErrorKind::AmbiguousPrefix => { | 88 )) |
90 CommandErrorKind::Abort(Some( | 89 } |
91 utf8_to_local(&format!( | 90 ListRevTrackedFilesError::UnsuportedRevlogVersion(version) => { |
92 "abort: ambiguous revision identifier {}\n", | 91 CommandError::Abort(Some( |
93 rev | 92 utf8_to_local(&format!( |
94 )) | 93 "abort: unsupported revlog version {}\n", |
95 .into(), | 94 version |
96 )) | 95 )) |
97 } | 96 .into(), |
98 ListRevTrackedFilesErrorKind::UnsuportedRevlogVersion(version) => { | 97 )) |
99 CommandErrorKind::Abort(Some( | 98 } |
100 utf8_to_local(&format!( | 99 ListRevTrackedFilesError::CorruptedRevlog => { |
101 "abort: unsupported revlog version {}\n", | 100 CommandError::Abort(Some("abort: corrupted revlog\n".into())) |
102 version | 101 } |
103 )) | 102 ListRevTrackedFilesError::UnknowRevlogDataFormat(format) => { |
104 .into(), | 103 CommandError::Abort(Some( |
104 utf8_to_local(&format!( | |
105 "abort: unknow revlog dataformat {:?}\n", | |
106 format | |
105 )) | 107 )) |
106 } | 108 .into(), |
107 ListRevTrackedFilesErrorKind::CorruptedRevlog => { | 109 )) |
108 CommandErrorKind::Abort(Some( | 110 } |
109 "abort: corrupted revlog\n".into(), | |
110 )) | |
111 } | |
112 ListRevTrackedFilesErrorKind::UnknowRevlogDataFormat(format) => { | |
113 CommandErrorKind::Abort(Some( | |
114 utf8_to_local(&format!( | |
115 "abort: unknow revlog dataformat {:?}\n", | |
116 format | |
117 )) | |
118 .into(), | |
119 )) | |
120 } | |
121 }, | |
122 } | 111 } |
123 } | 112 } |
124 | 113 |
125 /// Convert `ListDirstateTrackedFilesError` to `CommandError` | 114 /// Convert `ListDirstateTrackedFilesError` to `CommandError` |
126 fn map_dirstate_error(err: ListDirstateTrackedFilesError) -> CommandError { | 115 fn map_dirstate_error(err: ListDirstateTrackedFilesError) -> CommandError { |
127 CommandError { | 116 match err { |
128 kind: match err.kind { | 117 ListDirstateTrackedFilesError::IoError(err) => CommandError::Abort( |
129 ListDirstateTrackedFilesErrorKind::IoError(err) => { | 118 Some(utf8_to_local(&format!("abort: {}\n", err)).into()), |
130 CommandErrorKind::Abort(Some( | 119 ), |
131 utf8_to_local(&format!("abort: {}\n", err)).into(), | 120 ListDirstateTrackedFilesError::ParseError(_) => { |
132 )) | 121 CommandError::Abort(Some( |
133 } | 122 // TODO find a better error message |
134 ListDirstateTrackedFilesErrorKind::ParseError(_) => { | 123 b"abort: parse error\n".to_vec(), |
135 CommandErrorKind::Abort(Some( | 124 )) |
136 // TODO find a better error message | 125 } |
137 b"abort: parse error\n".to_vec(), | |
138 )) | |
139 } | |
140 }, | |
141 } | 126 } |
142 } | 127 } |