subrepo: force en_US.UTF-8 locale when calling svn
authorPatrick Mezard <pmezard@gmail.com>
Sat, 02 Jan 2010 16:42:00 +0100
changeset 10199 c2e2a5e6c36b
parent 10198 c2168d170f05
child 10200 3373ecddadba
subrepo: force en_US.UTF-8 locale when calling svn Parser only knows about en_US output. Forcing the encoding to UTF-8 might not be the best thing to do since the caller may receive some of the subversion output, but at least it should prevent conversion errors from svn client.
mercurial/subrepo.py
mercurial/util.py
--- a/mercurial/subrepo.py	Sat Jan 02 16:03:29 2010 +0100
+++ b/mercurial/subrepo.py	Sat Jan 02 16:42:00 2010 +0100
@@ -261,7 +261,10 @@
         cmd = ['svn'] + commands + [self._path]
         cmd = [util.shellquote(arg) for arg in cmd]
         cmd = util.quotecommand(' '.join(cmd))
-        write, read, err = util.popen3(cmd, newlines=True)
+        env = dict(os.environ)
+        for k in ('LANGUAGE', 'LANG', 'LC_ALL', 'LC_MESSAGES'):
+            env[k] = 'en_US.UTF-8'
+        write, read, err = util.popen3(cmd, env=env, newlines=True)
         retdata = read.read()
         err = err.read().strip()
         if err:
--- a/mercurial/util.py	Sat Jan 02 16:03:29 2010 +0100
+++ b/mercurial/util.py	Sat Jan 02 16:42:00 2010 +0100
@@ -39,22 +39,24 @@
 import subprocess
 closefds = os.name == 'posix'
 
-def popen2(cmd, newlines=False):
+def popen2(cmd, env=None, newlines=False):
     # Setting bufsize to -1 lets the system decide the buffer size.
     # The default for bufsize is 0, meaning unbuffered. This leads to
     # poor performance on Mac OS X: http://bugs.python.org/issue4194
     p = subprocess.Popen(cmd, shell=True, bufsize=-1,
                          close_fds=closefds,
                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-                         universal_newlines=newlines)
+                         universal_newlines=newlines,
+                         env=env)
     return p.stdin, p.stdout
 
-def popen3(cmd, newlines=False):
+def popen3(cmd, env=None, newlines=False):
     p = subprocess.Popen(cmd, shell=True, bufsize=-1,
                          close_fds=closefds,
                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE,
-                         universal_newlines=newlines)
+                         universal_newlines=newlines,
+                         env=env)
     return p.stdin, p.stdout, p.stderr
 
 def version():