Source

thg-qt-mq / losslesslocalstr.diff

Full commit
# HG changeset patch
# Parent 8f1b91111b43da784f44e05c81725fd407ebae0f
diff --git a/tests/hglib_encoding_test.py b/tests/hglib_encoding_test.py
--- a/tests/hglib_encoding_test.py
+++ b/tests/hglib_encoding_test.py
@@ -69,7 +69,6 @@ def test_tounicode_fallback():
     assert_equals(JAPANESE_KANA_I,
                   hglib.tounicode(JAPANESE_KANA_I.encode('euc-jp')))
 
-
 @with_encoding('euc-jp')
 def test_toutf():
     assert_equals(JAPANESE_KANA_I.encode('utf-8'),
diff --git a/tortoisehg/util/hglib.py b/tortoisehg/util/hglib.py
--- a/tortoisehg/util/hglib.py
+++ b/tortoisehg/util/hglib.py
@@ -46,6 +46,8 @@ def tounicode(s):
         return None
     if isinstance(s, unicode):
         return s
+    if isinstance(s, encoding.localstr):
+        return unicode(s._utf8, 'utf-8')
     for e in ('utf-8', _encoding):
         try:
             return s.decode(e, 'strict')
@@ -67,7 +69,7 @@ def fromunicode(s, errors='strict'):
     s = unicode(s)  # s can be QtCore.QString
     for enc in (_encoding, _fallbackencoding):
         try:
-            return s.encode(enc)
+            return encoding.localstr(s.encode('utf-8'), s.encode(enc))
         except UnicodeEncodeError:
             pass