Patchwork [2,of,4] logtoprocess: rewrite dict building in py3-compatible way

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 13, 2018, 1:42 p.m.
Message ID <f05dc9a1613a2086e8ef.1542116537@mimosa>
Download mbox | patch
Permalink /patch/36541/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 13, 2018, 1:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541907194 -32400
#      Sun Nov 11 12:33:14 2018 +0900
# Node ID f05dc9a1613a2086e8effb1dda5f446d52d5237f
# Parent  acd1e5000af16058913ff547e08a35d4583a6dac
logtoprocess: rewrite dict building in py3-compatible way

Patch

diff --git a/hgext/logtoprocess.py b/hgext/logtoprocess.py
--- a/hgext/logtoprocess.py
+++ b/hgext/logtoprocess.py
@@ -34,9 +34,11 @@  not ensure that they exit cleanly.
 
 from __future__ import absolute_import
 
-import itertools
 import os
 
+from mercurial import (
+    pycompat,
+)
 from mercurial.utils import (
     procutil,
 )
@@ -70,17 +72,16 @@  def uisetup(ui):
                     messages = (formatted,) + msg[1:]
                 else:
                     messages = msg
+                env = {
+                    b'EVENT': event,
+                    b'HGPID': os.getpid(),
+                }
                 # positional arguments are listed as MSG[N] keys in the
                 # environment
-                msgpairs = (
-                    ('MSG{0:d}'.format(i), m)
-                    for i, m in enumerate(messages, 1))
+                env.update((b'MSG%d' % i, m) for i, m in enumerate(messages, 1))
                 # keyword arguments get prefixed with OPT_ and uppercased
-                optpairs = (
-                    ('OPT_{0}'.format(key.upper()), value)
-                    for key, value in opts.iteritems())
-                env = dict(itertools.chain(msgpairs, optpairs),
-                           EVENT=event, HGPID=os.getpid())
+                env.update((b'OPT_%s' % key.upper(), value)
+                           for key, value in pycompat.byteskwargs(opts).items())
                 fullenv = procutil.shellenviron(env)
                 procutil.runbgcommand(script, fullenv, shell=True)
             return super(logtoprocessui, self).log(event, *msg, **opts)