[Updated] D8868: rhg: add a `Files` `Command` to prepare the `rhg files` subcommand
acezar (Antoine Cezar)
phabricator at mercurial-scm.org
Sat Aug 8 20:32:28 UTC 2020
Closed by commit rHG5fe25f8ef5d9: rhg: add a `Files` `Command` to prepare the `rhg files` subcommand (authored by acezar).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D8868?vs=22251&id=22363
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8868/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8868
AFFECTED FILES
rust/hg-core/src/lib.rs
rust/rhg/src/commands.rs
rust/rhg/src/commands/files.rs
rust/rhg/src/error.rs
CHANGE DETAILS
diff --git a/rust/rhg/src/error.rs b/rust/rhg/src/error.rs
--- a/rust/rhg/src/error.rs
+++ b/rust/rhg/src/error.rs
@@ -16,6 +16,8 @@
StdoutError,
/// The standard error stream cannot be written to
StderrError,
+ /// The command aborted
+ Abort(Option<Vec<u8>>),
}
impl CommandErrorKind {
@@ -25,6 +27,7 @@
CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT,
CommandErrorKind::StdoutError => exitcode::ABORT,
CommandErrorKind::StderrError => exitcode::ABORT,
+ CommandErrorKind::Abort(_) => exitcode::ABORT,
}
}
@@ -52,6 +55,7 @@
]
.concat(),
),
+ CommandErrorKind::Abort(message) => message.to_owned(),
_ => None,
}
}
diff --git a/rust/rhg/src/commands/files.rs b/rust/rhg/src/commands/files.rs
new file mode 100644
--- /dev/null
+++ b/rust/rhg/src/commands/files.rs
@@ -0,0 +1,50 @@
+use crate::commands::Command;
+use crate::error::{CommandError, CommandErrorKind};
+use crate::ui::Ui;
+use hg::operations::{ListTrackedFiles, ListTrackedFilesErrorKind};
+
+pub const HELP_TEXT: &str = "
+List tracked files.
+
+Returns 0 on success.
+";
+
+pub struct FilesCommand<'a> {
+ ui: &'a Ui,
+}
+
+impl<'a> FilesCommand<'a> {
+ pub fn new(ui: &'a Ui) -> Self {
+ FilesCommand { ui }
+ }
+}
+
+impl<'a> Command<'a> for FilesCommand<'a> {
+ fn run(&self) -> Result<(), CommandError> {
+ let operation_builder = ListTrackedFiles::new()?;
+ let operation = operation_builder.load().map_err(|err| {
+ CommandErrorKind::Abort(Some(
+ [b"abort: ", err.to_string().as_bytes(), b"\n"]
+ .concat()
+ .to_vec(),
+ ))
+ })?;
+ let files = operation.run().map_err(|err| match err.kind {
+ ListTrackedFilesErrorKind::ParseError(_) => {
+ CommandErrorKind::Abort(Some(
+ // TODO find a better error message
+ b"abort: parse error\n".to_vec(),
+ ))
+ }
+ })?;
+
+ let mut stdout = self.ui.stdout_buffer();
+ for file in files {
+ stdout.write_all(file.as_bytes())?;
+ stdout.write_all(b"\n")?;
+ }
+ stdout.flush()?;
+
+ Ok(())
+ }
+}
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 files;
pub mod root;
use crate::error::CommandError;
diff --git a/rust/hg-core/src/lib.rs b/rust/hg-core/src/lib.rs
--- a/rust/hg-core/src/lib.rs
+++ b/rust/hg-core/src/lib.rs
@@ -57,6 +57,7 @@
pub enum DirstateParseError {
TooLittleData,
Overflow,
+ // TODO refactor to use bytes instead of String
CorruptedEntry(String),
Damaged,
}
To: acezar, #hg-reviewers, Alphare, indygreg
Cc: indygreg, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200808/2abe9f4f/attachment-0002.html>
More information about the Mercurial-patches
mailing list