Patchwork [12,of,13] rust-chg: add interface to chdir the server

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 2, 2018, 2:25 p.m.
Message ID <a64ea1d912b6aa3328c0.1538490351@mimosa>
Download mbox | patch
Permalink /patch/35318/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 2, 2018, 2:25 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1537783590 -32400
#      Mon Sep 24 19:06:30 2018 +0900
# Node ID a64ea1d912b6aa3328c020f3cd1a9b8239bfcf25
# Parent  ac2fb97fe2c7b2bd3d9d5390db282620336c7912
rust-chg: add interface to chdir the server

Patch

diff --git a/rust/chg/src/clientext.rs b/rust/chg/src/clientext.rs
--- a/rust/chg/src/clientext.rs
+++ b/rust/chg/src/clientext.rs
@@ -6,8 +6,11 @@ 
 //! cHg extensions to command server client.
 
 use std::ffi::OsStr;
+use std::os::unix::ffi::OsStrExt;
 use std::os::unix::io::AsRawFd;
+use std::path::Path;
 use tokio_hglib::{Client, Connection};
+use tokio_hglib::protocol::OneShotRequest;
 
 use super::attachio::AttachIo;
 use super::message;
@@ -23,6 +26,10 @@  pub trait ChgClientExt<C>
               O: AsRawFd,
               E: AsRawFd;
 
+    /// Changes the working directory of the server.
+    fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
+        where P: AsRef<Path>;
+
     /// Runs the specified Mercurial command with cHg extension.
     fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
         where I: IntoIterator<Item = P>,
@@ -41,6 +48,12 @@  impl<C> ChgClientExt<C> for Client<C>
         AttachIo::with_client(self, stdin, stdout, Some(stderr))
     }
 
+    fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
+        where P: AsRef<Path>,
+    {
+        OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes())
+    }
+
     fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
         where I: IntoIterator<Item = P>,
               P: AsRef<OsStr>,