Patchwork [1,of,3] chg: send type information via S channel (BC)

login
register
mail settings
Submitter Jun Wu
Date Jan. 6, 2017, 4:17 p.m.
Message ID <530b32a20c085fd9819b.1483719476@x1c>
Download mbox | patch
Permalink /patch/18125/
State Accepted
Headers show

Comments

Jun Wu - Jan. 6, 2017, 4:17 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1483719063 0
#      Fri Jan 06 16:11:03 2017 +0000
# Node ID 530b32a20c085fd9819bad3235ffbca5f98095ea
# Parent  011122b3b1c42374fb0489d107418e1be3665ca6
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 530b32a20c08
chg: send type information via S channel (BC)

Previously S channel is only used to send system commands. It will also be
used to send pager commands. So add a type parameter.

This breaks older chg clients. But chg and hg should always come from a
single commit and be packed into a single package. Supporting running
inconsistent versions of chg and hg seems to be unnecessarily complicated
with little benefit. So just make the change and assume people won't use
inconsistent chg with hg.

Patch

diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -238,8 +238,8 @@  static void handlesystemrequest(hgclient
 
 	const char **args = unpackcmdargsnul(ctx);
-	if (!args[0] || !args[1])
-		abortmsg("missing command or cwd in system request");
-	debugmsg("run '%s' at '%s'", args[0], args[1]);
-	int32_t r = runshellcmd(args[0], args + 2, args[1]);
+	if (!args[0] || !args[1] || !args[2])
+		abortmsg("missing type or command or cwd in system request");
+	debugmsg("run '%s' at '%s'", args[1], args[2]);
+	int32_t r = runshellcmd(args[1], args + 3, args[2]);
 	free(args);
 
diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -288,4 +288,5 @@  class channeledsystem(object):
 
     payload length (unsigned int),
+    type, '\0',
     cmd, '\0',
     cwd, '\0',
@@ -294,5 +295,5 @@  class channeledsystem(object):
     envkey, '=', val
 
-    and waits:
+    if type == 'system', waits for:
 
     exitcode length (unsigned int),
@@ -304,6 +305,6 @@  class channeledsystem(object):
         self.channel = channel
 
-    def __call__(self, cmd, environ, cwd):
-        args = [util.quotecommand(cmd), os.path.abspath(cwd or '.')]
+    def __call__(self, cmd, environ, cwd, type='system'):
+        args = [type, util.quotecommand(cmd), os.path.abspath(cwd or '.')]
         args.extend('%s=%s' % (k, v) for k, v in environ.iteritems())
         data = '\0'.join(args)