logtoprocess: leverage procutil.shellenviron() to stringify variables (BC)
authorYuya Nishihara <yuya@tcha.org>
Sun, 11 Nov 2018 12:27:23 +0900
changeset 40619 fbac323eb625
parent 40618 ff8b2886c492
child 40620 b2e5a554bc7b
logtoprocess: leverage procutil.shellenviron() to stringify variables (BC) This should make the extension more Py3 friendly. The environment variables of the main process are copied to the dict by shellenviron(). .. bc:: Boolean options passed to the logtoprocess extension are now formatted as ``0`` or ``1`` instead of ``None``, ``False``, or ``True``.
hgext/logtoprocess.py
--- a/hgext/logtoprocess.py	Tue Nov 13 22:15:30 2018 +0900
+++ b/hgext/logtoprocess.py	Sun Nov 11 12:27:23 2018 +0900
@@ -73,16 +73,16 @@
                 # positional arguments are listed as MSG[N] keys in the
                 # environment
                 msgpairs = (
-                    ('MSG{0:d}'.format(i), str(m))
+                    ('MSG{0:d}'.format(i), m)
                     for i, m in enumerate(messages, 1))
                 # keyword arguments get prefixed with OPT_ and uppercased
                 optpairs = (
-                    ('OPT_{0}'.format(key.upper()), str(value))
+                    ('OPT_{0}'.format(key.upper()), value)
                     for key, value in opts.iteritems())
-                env = dict(itertools.chain(procutil.shellenviron().items(),
-                                           msgpairs, optpairs),
-                           EVENT=event, HGPID=str(os.getpid()))
-                procutil.runbgcommand(script, env, shell=True)
+                env = dict(itertools.chain(msgpairs, optpairs),
+                           EVENT=event, HGPID=os.getpid())
+                fullenv = procutil.shellenviron(env)
+                procutil.runbgcommand(script, fullenv, shell=True)
             return super(logtoprocessui, self).log(event, *msg, **opts)
 
     # Replace the class for this instance and all clones created from it: