##// END OF EJS Templates
chg: fallback to original hg if stdio fds are missing...
chg: fallback to original hg if stdio fds are missing If stdio fds are missing (ex. fd 0 is not present), chg might open fds that take the numbers 0, and attachio would send the wrong fds to the client, which might cause unwanted behaviors. Avoid that by detecting the missing fds and falling back to the original hg. Differential Revision: https://phab.mercurial-scm.org/D9058

File last commit:

r46009:ed95ccc9 default
r46093:5eee6f4f default
Show More
files.rs
58 lines | 1.7 KiB | application/rls-services+xml | RustLexer
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923 use crate::commands::Command;
use crate::error::{CommandError, CommandErrorKind};
use crate::ui::Ui;
use hg::operations::{ListTrackedFiles, ListTrackedFilesErrorKind};
Raphaël Gomès
rhg: make output of `files` relative to the current directory and the root...
r46007 use hg::utils::files::{get_bytes_from_path, relativize_path};
use hg::utils::hg_path::HgPathBuf;
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923
pub const HELP_TEXT: &str = "
List tracked files.
Returns 0 on success.
";
Antoine Cezar
rhg: pass `ui` to `Command` `run`...
r46009 pub struct FilesCommand {}
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923
Antoine Cezar
rhg: pass `ui` to `Command` `run`...
r46009 impl FilesCommand {
pub fn new() -> Self {
FilesCommand {}
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923 }
}
Antoine Cezar
rhg: pass `ui` to `Command` `run`...
r46009 impl Command for FilesCommand {
fn run(&self, ui: &Ui) -> Result<(), CommandError> {
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923 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(),
))
}
})?;
Raphaël Gomès
rhg: make output of `files` relative to the current directory and the root...
r46007 let cwd = std::env::current_dir()
.or_else(|e| Err(CommandErrorKind::CurrentDirNotFound(e)))?;
let rooted_cwd = cwd
.strip_prefix(operation_builder.get_root())
.expect("cwd was already checked within the repository");
let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd));
Antoine Cezar
rhg: pass `ui` to `Command` `run`...
r46009 let mut stdout = ui.stdout_buffer();
Raphaël Gomès
rhg: make output of `files` relative to the current directory and the root...
r46007
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923 for file in files {
Raphaël Gomès
rhg: make output of `files` relative to the current directory and the root...
r46007 stdout.write_all(relativize_path(file, &rooted_cwd).as_ref())?;
Antoine Cezar
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
r45923 stdout.write_all(b"\n")?;
}
stdout.flush()?;
Ok(())
}
}