Patchwork D8383: rust-chg: update name of the server process

login
register
mail settings
Submitter phabricator
Date April 6, 2020, 2:19 p.m.
Message ID <differential-rev-PHID-DREV-sxijraizzxdwotf56irs-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46030/
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.

REVISION SUMMARY
  This is a copy of updateprocname() of hgclient.c.
  
  At this point, rust-chg is basically functional. I did dogfooding for
  a couple of weeks in 2018. There are a few remaining tasks:
  
  a. loop detection by CHGINTERNALMARK
   b. forward unsupported commands (notably serve -d) to real hg
   c. better handling of early server exception
   d. modernize codebase (2018 edition, impl trait, async/await)
  
  For (d), we'll probably want to switch to async-std, but I'm thinking of
  upgrading to Tokio 0.2 as an intermediate step since process API isn't
  ported to async-std yet. I'm pretty sure future migration to async-std
  will be painless compared to the mass rewrite from futures-0.1 to 0.3.
  
  https://github.com/async-rs/async-std/issues/22

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/chg/src/clientext.rs
  rust/chg/src/locator.rs

CHANGE DETAILS




To: yuja, #hg-reviewers
Cc: mercurial-devel
phabricator - April 8, 2020, 8:47 a.m.
Alphare added a comment.
Alphare accepted this revision.


  > For (d) [modernizing the codebase],  we'll probably want to switch to async-std, but I'm thinking of
  > upgrading to Tokio 0.2 as an intermediate step since process API isn't
  > ported to async-std yet. I'm pretty sure future migration to async-std
  > will be painless compared to the mass rewrite from futures-0.1 to 0.3.
  
  That seems reasonable indeed.
  
  There is also a potentially interesting project we need to keep an eye out for, since it's made by the same person that started `async-std` in the first place: https://stjepang.github.io/2020/04/03/why-im-building-a-new-async-runtime.html. I have to admit that the constant rewrites of async runtimes (or lack thereof) does not help when making a decision and are not really reassuring, but I guess it's a new-ish problem in the Rust ecosystem.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8383/new/

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

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

Patch

diff --git a/rust/chg/src/locator.rs b/rust/chg/src/locator.rs
--- a/rust/chg/src/locator.rs
+++ b/rust/chg/src/locator.rs
@@ -196,6 +196,17 @@ 
                 Ok((loc, client))
             })
             .and_then(|(loc, client)| {
+                // It's purely optional, and the server might not support this command.
+                if client.server_spec().capabilities.contains("setprocname") {
+                    let fut = client
+                        .set_process_name(format!("chg[worker/{}]", loc.process_id))
+                        .map(|client| (loc, client));
+                    Either::A(fut)
+                } else {
+                    Either::B(future::ok((loc, client)))
+                }
+            })
+            .and_then(|(loc, client)| {
                 client
                     .set_current_dir(&loc.current_dir)
                     .map(|client| (loc, client))
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
@@ -42,6 +42,11 @@ 
         I: IntoIterator<Item = (P, P)>,
         P: AsRef<OsStr>;
 
+    /// Changes the process title of the server.
+    fn set_process_name<P>(self, name: P) -> OneShotRequest<C>
+    where
+        P: AsRef<OsStr>;
+
     /// Changes the umask of the server process.
     fn set_umask(self, mask: u32) -> OneShotRequest<C>;
 
@@ -94,6 +99,13 @@ 
         OneShotRequest::start_with_args(self, b"setenv", message::pack_env_vars_os(vars))
     }
 
+    fn set_process_name<P>(self, name: P) -> OneShotRequest<C>
+    where
+        P: AsRef<OsStr>,
+    {
+        OneShotRequest::start_with_args(self, b"setprocname", name.as_ref().as_bytes())
+    }
+
     fn set_umask(self, mask: u32) -> OneShotRequest<C> {
         let mut args = BytesMut::with_capacity(mem::size_of_val(&mask));
         args.put_u32_be(mask);