Commits

Yuya Nishihara  committed 60c91cf

hgext: update default encoding by LANG or HGENCODING change

  • Participants
  • Parent commits 7f7ecb5

Comments (0)

Files changed (2)

File hgext/chgsupport.py

 """
 
 import errno, gc, itertools, os, signal, socket, struct, tempfile
-from mercurial import cmdutil, commands, commandserver, dispatch, error, \
-                      extensions, i18n, scmutil, util
+from mercurial import cmdutil, commands, commandserver, dispatch, encoding, \
+                      error, extensions, i18n, scmutil, util
 from mercurial.i18n import _
 
 class channeledinput(commandserver.channeledinput):
         return False
 
 _envmodstoreload = [
-    ('LANG LANGUAGE LC_MESSAGES'.split(), [i18n]),  # recreate gettext 't'
+    # recreate gettext 't' by reloading i18n
+    ('LANG LANGUAGE LC_MESSAGES'.split(), [encoding, i18n]),
+    ('HGENCODING HGENCODINGMODE HGENCODINGAMBIGUOUS'.split(), [encoding]),
     ]
 
 def _listmodstoreload(newenv):
             toreload.update(mods)
     return toreload
 
+def _fixdefaultencoding():
+    """Apply new default encoding to commands table"""
+    newdefaults = {'encoding': encoding.encoding,
+                   'encodingmode': encoding.encodingmode}
+    for i, opt in enumerate(commands.globalopts):
+        name = opt[1]
+        newdef = newdefaults.get(name)
+        if newdef is not None:
+            commands.globalopts[i] = opt[:2] + (newdef,) + opt[3:]
+
 class chgcmdserver(commandserver.server):
     def __init__(self, sui, ui, repo, fin, fout, masterpid):
         super(chgcmdserver, self).__init__(ui, repo, mode='pipe')
         for mod in modstoreload:
             self._sui.debug('reload %s module\n' % mod.__name__)
             reload(mod)
+        if encoding in modstoreload:
+            _fixdefaultencoding()
 
     capabilities = commandserver.server.capabilities.copy()
     capabilities.update({'chdir': chdir,

File tests/run-hgtests.py

     }
 
 # switch background server by environment variables (SHOULD BE FIXED LATER)
-_defaultenvsuminclude = ['HGENCODING', 'HGENCODINGMODE', 'HGENCODINGAMBIGUOUS']
+_defaultenvsuminclude = []
 _envsuminclude = {
     'test-alias.t': _defaultenvsuminclude + ['FOO'],
     'test-convert-svn-branches.t': _defaultenvsuminclude + ['HG'],