merge with stable
authorMatt Mackall <mpm@selenic.com>
Fri, 15 Apr 2011 23:46:59 -0500
changeset 13941 924f40b977ee
parent 13939 ed22a26fc7c6 (current diff)
parent 13940 b7b26e54e37a (diff)
child 13942 88f0e41d8802
merge with stable
--- a/mercurial/encoding.py	Fri Apr 15 20:35:59 2011 -0500
+++ b/mercurial/encoding.py	Fri Apr 15 23:46:59 2011 -0500
@@ -95,11 +95,15 @@
     for e in ('UTF-8', fallbackencoding):
         try:
             u = s.decode(e) # attempt strict decoding
-            if e == 'UTF-8':
-                return localstr(s, u.encode(encoding, "replace"))
+            r = u.encode(encoding, "replace")
+            if u == r.decode(encoding):
+                # r is a safe, non-lossy encoding of s
+                return r
+            elif e == 'UTF-8':
+                return localstr(s, r)
             else:
-                return localstr(u.encode('UTF-8'),
-                                u.encode(encoding, "replace"))
+                return localstr(u.encode('UTF-8'), r)
+
         except LookupError, k:
             raise error.Abort("%s, please check your locale settings" % k)
         except UnicodeDecodeError:
--- a/tests/test-encoding.t	Fri Apr 15 20:35:59 2011 -0500
+++ b/tests/test-encoding.t	Fri Apr 15 23:46:59 2011 -0500
@@ -241,3 +241,9 @@
   [255]
   $ cp latin-1-tag .hg/branch
   $ HGENCODING=latin-1 hg ci -m 'auto-promote legacy name'
+
+Test roundtrip encoding of lookup tables when not using UTF-8 (issue2763)
+
+  $ HGENCODING=latin-1 hg up `cat latin-1-tag`
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+