##// END OF EJS Templates
rust-dependencies: update `regex` to 1.3.9...
rust-dependencies: update `regex` to 1.3.9 Version `1.3.8` introduces support for empty alternations, which makes previously disallowed patterns usable in `regex`. From a user's perspective, this means that glob patterns like `*.py{,c}` will no longer generate an "invalid" regex and will use the Rust path. `1.3.9` is a bugfix release, might as well update to the latest one. Differential Revision: https://phab.mercurial-scm.org/D8593

File last commit:

r45236:d6f70692 default
r45405:4313a0d7 default
Show More
clientext.rs
121 lines | 3.9 KiB | application/rls-services+xml | RustLexer
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 // Copyright 2018 Yuya Nishihara <yuya@tcha.org>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
//! cHg extensions to command server client.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 use bytes::{BufMut, BytesMut};
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 use std::ffi::OsStr;
Yuya Nishihara
rust-chg: add interface to run "validate" request...
r45171 use std::io;
Yuya Nishihara
rust-chg: send client side umask to server...
r45174 use std::mem;
Yuya Nishihara
rust-chg: add interface to chdir the server
r40014 use std::os::unix::ffi::OsStrExt;
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 use std::os::unix::io::AsRawFd;
Yuya Nishihara
rust-chg: add interface to chdir the server
r40014 use std::path::Path;
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 use tokio_hglib::UnixClient;
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 use crate::attachio;
use crate::message::{self, Instruction, ServerSpec};
use crate::runcommand;
Yuya Nishihara
rust-chg: use "crate::" to import local modules...
r45180 use crate::uihandler::SystemHandler;
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 /// Command-server client that also supports cHg extensions.
pub struct ChgClient {
client: UnixClient,
}
impl ChgClient {
/// Connects to a command server listening at the specified socket path.
pub async fn connect(path: impl AsRef<Path>) -> io::Result<Self> {
let client = UnixClient::connect(path).await?;
Ok(ChgClient { client })
}
/// Server capabilities, encoding, etc.
pub fn server_spec(&self) -> &ServerSpec {
self.client.server_spec()
}
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 /// Attaches the client file descriptors to the server.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn attach_io(
&mut self,
stdin: &impl AsRawFd,
stdout: &impl AsRawFd,
stderr: &impl AsRawFd,
) -> io::Result<()> {
attachio::attach_io(self.client.borrow_protocol_mut(), stdin, stdout, stderr).await
}
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013
Yuya Nishihara
rust-chg: add interface to chdir the server
r40014 /// Changes the working directory of the server.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn set_current_dir(&mut self, dir: impl AsRef<Path>) -> io::Result<()> {
let dir_bytes = dir.as_ref().as_os_str().as_bytes().to_owned();
self.client
.borrow_protocol_mut()
.send_command_with_args("chdir", dir_bytes)
.await
}
Yuya Nishihara
rust-chg: add interface to chdir the server
r40014
Yuya Nishihara
rust-chg: send client-side environment variables to server...
r45165 /// Updates the environment variables of the server.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn set_env_vars_os(
&mut self,
Yuya Nishihara
rust-chg: leverage impl trait at argument position...
r45183 vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 ) -> io::Result<()> {
self.client
.borrow_protocol_mut()
.send_command_with_args("setenv", message::pack_env_vars_os(vars))
.await
}
Yuya Nishihara
rust-chg: send client-side environment variables to server...
r45165
Yuya Nishihara
rust-chg: update name of the server process...
r45175 /// Changes the process title of the server.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn set_process_name(&mut self, name: impl AsRef<OsStr>) -> io::Result<()> {
let name_bytes = name.as_ref().as_bytes().to_owned();
self.client
.borrow_protocol_mut()
.send_command_with_args("setprocname", name_bytes)
.await
}
Yuya Nishihara
rust-chg: update name of the server process...
r45175
Yuya Nishihara
rust-chg: send client side umask to server...
r45174 /// Changes the umask of the server process.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn set_umask(&mut self, mask: u32) -> io::Result<()> {
let mut mask_bytes = BytesMut::with_capacity(mem::size_of_val(&mask));
mask_bytes.put_u32(mask);
self.client
.borrow_protocol_mut()
.send_command_with_args("setumask2", mask_bytes)
.await
}
Yuya Nishihara
rust-chg: send client side umask to server...
r45174
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 /// Runs the specified Mercurial command with cHg extension.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn run_command_chg(
&mut self,
handler: &mut impl SystemHandler,
Yuya Nishihara
rust-chg: leverage impl trait at argument position...
r45183 args: impl IntoIterator<Item = impl AsRef<OsStr>>,
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 ) -> io::Result<i32> {
runcommand::run_command(
self.client.borrow_protocol_mut(),
handler,
message::pack_args_os(args),
)
.await
}
Yuya Nishihara
rust-chg: add interface to run "validate" request...
r45171
/// Validates if the server can run Mercurial commands with the expected
/// configuration.
///
/// The `args` should contain early command arguments such as `--config`
/// and `-R`.
///
/// Client-side environment must be sent prior to this request, by
/// `set_current_dir()` and `set_env_vars_os()`.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn validate(
&mut self,
Yuya Nishihara
rust-chg: leverage impl trait at argument position...
r45183 args: impl IntoIterator<Item = impl AsRef<OsStr>>,
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 ) -> io::Result<Vec<Instruction>> {
let data = self
.client
.borrow_protocol_mut()
.query_with_args("validate", message::pack_args_os(args))
.await?;
message::parse_instructions(data)
Yuya Nishihara
rust-chg: add interface to run "validate" request...
r45171 }
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 }