Patchwork [9,of,9] chgserver: implement a simple "runcommand"

login
register
mail settings
Submitter Jun Wu
Date Nov. 13, 2016, 9:55 p.m.
Message ID <b923b234b9032cdd87e6.1479074153@x1c>
Download mbox | patch
Permalink /patch/17558/
State Changes Requested
Headers show

Comments

Jun Wu - Nov. 13, 2016, 9:55 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1479073486 0
#      Sun Nov 13 21:44:46 2016 +0000
# Node ID b923b234b9032cdd87e6519dae7fbfdd292b7b40
# Parent  4660680374d24f7d46834b54de2fbbeec164e906
chgserver: implement a simple "runcommand"

Although the chgserver could just use command server's runcommand. The new
design could be very simple - no need to do ui copying etc. So let's write
it down explicitly to use the simple version.

Future patches improving the pager area also requires a different
"runcommand" from the "commandserver" version.
Yuya Nishihara - Nov. 19, 2016, 9:06 a.m.
On Sun, 13 Nov 2016 21:55:53 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1479073486 0
> #      Sun Nov 13 21:44:46 2016 +0000
> # Node ID b923b234b9032cdd87e6519dae7fbfdd292b7b40
> # Parent  4660680374d24f7d46834b54de2fbbeec164e906
> chgserver: implement a simple "runcommand"
> 
> Although the chgserver could just use command server's runcommand. The new
> design could be very simple - no need to do ui copying etc. So let's write
> it down explicitly to use the simple version.
> 
> Future patches improving the pager area also requires a different
> "runcommand" from the "commandserver" version.
> 
> diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
> --- a/mercurial/chgserver.py
> +++ b/mercurial/chgserver.py
> @@ -438,4 +438,12 @@ class chgcmdserver(commandserver.server)
>          os.chdir(path)
>  
> +    def runcommand(self):
> +        """Reads a list of \0 terminated arguments, executes and writes the
> +        return code to the result channel"""
> +        args = self._readlist()
> +        req = dispatch.request(args[:])

self.cin/cout/cerr should be passed for correctness. The server doesn't
guarantee they are replaced with std streams by attachio.

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -438,4 +438,12 @@  class chgcmdserver(commandserver.server)
         os.chdir(path)
 
+    def runcommand(self):
+        """Reads a list of \0 terminated arguments, executes and writes the
+        return code to the result channel"""
+        args = self._readlist()
+        req = dispatch.request(args[:])
+        ret = (dispatch.dispatch(req) or 0) & 255 # might return None
+        self.cresult.write(struct.pack('>i', int(ret)))
+
     def setumask(self):
         """Change umask"""
@@ -461,4 +469,5 @@  class chgcmdserver(commandserver.server)
     capabilities.update({'attachio': attachio,
                          'chdir': chdir,
+                         'runcommand': runcommand,
                          'setenv': setenv,
                          'setumask': setumask})