[Updated] D8960: rhg: add a `DebugData` `Command` to prepare the `rhg debugdata` subcommand
acezar (Antoine Cezar)
phabricator at mercurial-scm.org
Mon Aug 31 14:40:27 UTC 2020
acezar marked an inline comment as done.
acezar updated this revision to Diff 22493.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D8960?vs=22460&id=22493
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8960/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8960
AFFECTED FILES
rust/hg-core/src/operations/mod.rs
rust/rhg/src/commands.rs
rust/rhg/src/commands/debugdata.rs
CHANGE DETAILS
diff --git a/rust/rhg/src/commands/debugdata.rs b/rust/rhg/src/commands/debugdata.rs
new file mode 100644
--- /dev/null
+++ b/rust/rhg/src/commands/debugdata.rs
@@ -0,0 +1,52 @@
+use crate::commands::Command;
+use crate::error::{CommandError, CommandErrorKind};
+use crate::ui::Ui;
+use hg::operations::{
+ DebugData, DebugDataError, DebugDataErrorKind, DebugDataKind,
+};
+
+pub const HELP_TEXT: &str = "
+Dump the contents of a data file revision
+";
+
+pub struct DebugDataCommand<'a> {
+ rev: &'a str,
+ kind: DebugDataKind,
+}
+
+impl<'a> DebugDataCommand<'a> {
+ pub fn new(rev: &'a str, kind: DebugDataKind) -> Self {
+ DebugDataCommand { rev, kind }
+ }
+}
+
+impl<'a> Command for DebugDataCommand<'a> {
+ fn run(&self, ui: &Ui) -> Result<(), CommandError> {
+ let mut operation = DebugData::new(self.rev, self.kind);
+ let data =
+ operation.run().map_err(|e| to_command_error(self.rev, e))?;
+
+ let mut stdout = ui.stdout_buffer();
+ stdout.write_all(&data)?;
+ stdout.flush()?;
+
+ Ok(())
+ }
+}
+
+/// Convert operation errors to command errors
+fn to_command_error(rev: &str, err: DebugDataError) -> CommandError {
+ match err.kind {
+ DebugDataErrorKind::FindRootError(err) => CommandError::from(err),
+ DebugDataErrorKind::IoError(err) => CommandError {
+ kind: CommandErrorKind::Abort(Some(
+ format!("abort: {}\n", err).into(),
+ )),
+ },
+ DebugDataErrorKind::InvalidRevision => CommandError {
+ kind: CommandErrorKind::Abort(Some(
+ format!("abort: invalid revision identifier{}\n", rev).into(),
+ )),
+ },
+ }
+}
diff --git a/rust/rhg/src/commands.rs b/rust/rhg/src/commands.rs
--- a/rust/rhg/src/commands.rs
+++ b/rust/rhg/src/commands.rs
@@ -1,3 +1,4 @@
+pub mod debugdata;
pub mod files;
pub mod root;
use crate::error::CommandError;
diff --git a/rust/hg-core/src/operations/mod.rs b/rust/hg-core/src/operations/mod.rs
--- a/rust/hg-core/src/operations/mod.rs
+++ b/rust/hg-core/src/operations/mod.rs
@@ -6,6 +6,9 @@
mod dirstate_status;
mod find_root;
mod list_tracked_files;
+pub use debugdata::{
+ DebugData, DebugDataError, DebugDataErrorKind, DebugDataKind,
+};
pub use find_root::{FindRoot, FindRootError, FindRootErrorKind};
pub use list_tracked_files::{
ListTrackedFiles, ListTrackedFilesError, ListTrackedFilesErrorKind,
To: acezar, #hg-reviewers
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200831/f8779cd7/attachment-0002.html>
More information about the Mercurial-patches
mailing list