Patchwork D8379: rust-chg: add interface to run "validate" request

login
register
mail settings
Submitter phabricator
Date April 6, 2020, 2:19 p.m.
Message ID <differential-rev-PHID-DREV-oza32xtiqfkq6quod7n6-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46027/
State Superseded
Headers show

Comments

phabricator - April 6, 2020, 2:19 p.m.
yuja created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8379

AFFECTED FILES
  rust/chg/src/clientext.rs

CHANGE DETAILS




To: yuja, #hg-reviewers
Cc: mercurial-devel

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
@@ -5,15 +5,17 @@ 
 
 //! cHg extensions to command server client.
 
+use bytes::Bytes;
 use std::ffi::OsStr;
+use std::io;
 use std::os::unix::ffi::OsStrExt;
 use std::os::unix::io::AsRawFd;
 use std::path::Path;
-use tokio_hglib::protocol::OneShotRequest;
+use tokio_hglib::protocol::{OneShotQuery, OneShotRequest};
 use tokio_hglib::{Client, Connection};
 
 use super::attachio::AttachIo;
-use super::message;
+use super::message::{self, Instruction};
 use super::runcommand::ChgRunCommand;
 use super::uihandler::SystemHandler;
 
@@ -45,6 +47,19 @@ 
         I: IntoIterator<Item = P>,
         P: AsRef<OsStr>,
         H: SystemHandler;
+
+    /// 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()`.
+    fn validate<I, P>(self, args: I) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>
+    where
+        I: IntoIterator<Item = P>,
+        P: AsRef<OsStr>;
 }
 
 impl<C> ChgClientExt<C> for Client<C>
@@ -83,4 +98,17 @@ 
     {
         ChgRunCommand::with_client(self, handler, message::pack_args_os(args))
     }
+
+    fn validate<I, P>(self, args: I) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>
+    where
+        I: IntoIterator<Item = P>,
+        P: AsRef<OsStr>,
+    {
+        OneShotQuery::start_with_args(
+            self,
+            b"validate",
+            message::pack_args_os(args),
+            message::parse_instructions,
+        )
+    }
 }