Show More
@@ -0,0 +1,80 b'' | |||
|
1 | use crate::commands::Command; | |
|
2 | use crate::error::{CommandError, CommandErrorKind}; | |
|
3 | use crate::ui::utf8_to_local; | |
|
4 | use crate::ui::Ui; | |
|
5 | use hg::operations::{ | |
|
6 | DebugData, DebugDataError, DebugDataErrorKind, DebugDataKind, | |
|
7 | }; | |
|
8 | ||
|
9 | pub const HELP_TEXT: &str = " | |
|
10 | Dump the contents of a data file revision | |
|
11 | "; | |
|
12 | ||
|
13 | pub struct DebugDataCommand<'a> { | |
|
14 | rev: &'a str, | |
|
15 | kind: DebugDataKind, | |
|
16 | } | |
|
17 | ||
|
18 | impl<'a> DebugDataCommand<'a> { | |
|
19 | pub fn new(rev: &'a str, kind: DebugDataKind) -> Self { | |
|
20 | DebugDataCommand { rev, kind } | |
|
21 | } | |
|
22 | } | |
|
23 | ||
|
24 | impl<'a> Command for DebugDataCommand<'a> { | |
|
25 | fn run(&self, ui: &Ui) -> Result<(), CommandError> { | |
|
26 | let mut operation = DebugData::new(self.rev, self.kind); | |
|
27 | let data = | |
|
28 | operation.run().map_err(|e| to_command_error(self.rev, e))?; | |
|
29 | ||
|
30 | let mut stdout = ui.stdout_buffer(); | |
|
31 | stdout.write_all(&data)?; | |
|
32 | stdout.flush()?; | |
|
33 | ||
|
34 | Ok(()) | |
|
35 | } | |
|
36 | } | |
|
37 | ||
|
38 | /// Convert operation errors to command errors | |
|
39 | fn to_command_error(rev: &str, err: DebugDataError) -> CommandError { | |
|
40 | match err.kind { | |
|
41 | DebugDataErrorKind::FindRootError(err) => CommandError::from(err), | |
|
42 | DebugDataErrorKind::IoError(err) => CommandError { | |
|
43 | kind: CommandErrorKind::Abort(Some( | |
|
44 | utf8_to_local(&format!("abort: {}\n", err)).into(), | |
|
45 | )), | |
|
46 | }, | |
|
47 | DebugDataErrorKind::InvalidRevision => CommandError { | |
|
48 | kind: CommandErrorKind::Abort(Some( | |
|
49 | utf8_to_local(&format!( | |
|
50 | "abort: invalid revision identifier{}\n", | |
|
51 | rev | |
|
52 | )) | |
|
53 | .into(), | |
|
54 | )), | |
|
55 | }, | |
|
56 | DebugDataErrorKind::UnsuportedRevlogVersion(version) => CommandError { | |
|
57 | kind: CommandErrorKind::Abort(Some( | |
|
58 | utf8_to_local(&format!( | |
|
59 | "abort: unsupported revlog version {}\n", | |
|
60 | version | |
|
61 | )) | |
|
62 | .into(), | |
|
63 | )), | |
|
64 | }, | |
|
65 | DebugDataErrorKind::CorruptedRevlog => CommandError { | |
|
66 | kind: CommandErrorKind::Abort(Some( | |
|
67 | "abort: corrupted revlog\n".into(), | |
|
68 | )), | |
|
69 | }, | |
|
70 | DebugDataErrorKind::UnknowRevlogDataFormat(format) => CommandError { | |
|
71 | kind: CommandErrorKind::Abort(Some( | |
|
72 | utf8_to_local(&format!( | |
|
73 | "abort: unknow revlog dataformat {:?}\n", | |
|
74 | format | |
|
75 | )) | |
|
76 | .into(), | |
|
77 | )), | |
|
78 | }, | |
|
79 | } | |
|
80 | } |
@@ -6,6 +6,9 b' mod debugdata;' | |||
|
6 | 6 | mod dirstate_status; |
|
7 | 7 | mod find_root; |
|
8 | 8 | mod list_tracked_files; |
|
9 | pub use debugdata::{ | |
|
10 | DebugData, DebugDataError, DebugDataErrorKind, DebugDataKind, | |
|
11 | }; | |
|
9 | 12 | pub use find_root::{FindRoot, FindRootError, FindRootErrorKind}; |
|
10 | 13 | pub use list_tracked_files::{ |
|
11 | 14 | ListTrackedFiles, ListTrackedFilesError, ListTrackedFilesErrorKind, |
@@ -1,3 +1,4 b'' | |||
|
1 | pub mod debugdata; | |
|
1 | 2 | pub mod files; |
|
2 | 3 | pub mod root; |
|
3 | 4 | use crate::error::CommandError; |
@@ -1,3 +1,4 b'' | |||
|
1 | use std::borrow::Cow; | |
|
1 | 2 | use std::io; |
|
2 | 3 | use std::io::{ErrorKind, Write}; |
|
3 | 4 | |
@@ -103,3 +104,10 b' fn handle_stderr_error(error: io::Error)' | |||
|
103 | 104 | } |
|
104 | 105 | Err(UiError::StdoutError(error)) |
|
105 | 106 | } |
|
107 | ||
|
108 | /// Encode rust strings according to the user system. | |
|
109 | pub fn utf8_to_local(s: &str) -> Cow<[u8]> { | |
|
110 | // TODO encode for the user's system // | |
|
111 | let bytes = s.as_bytes(); | |
|
112 | Cow::Borrowed(bytes) | |
|
113 | } |
General Comments 0
You need to be logged in to leave comments.
Login now