Mercurial > hg
diff mercurial/util.py @ 9567:02c43e8e0835
Merge with hg-i18n-stable
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Wed, 30 Sep 2009 21:14:24 +0200 |
parents | 4c3fb45123e5 b2d65ee49a72 |
children | ceb0f59e1327 |
line wrap: on
line diff
--- a/mercurial/util.py Tue Sep 29 00:54:15 2009 +0200 +++ b/mercurial/util.py Wed Sep 30 21:14:24 2009 +0200 @@ -14,7 +14,7 @@ """ from i18n import _ -import error, osutil +import error, osutil, encoding import cStringIO, errno, re, shutil, sys, tempfile, traceback import os, stat, time, calendar, random, textwrap import imp @@ -1278,7 +1278,14 @@ # adjust for weird terminal size width = max(78, hangindent + 1) padding = '\n' + ' ' * hangindent - return padding.join(textwrap.wrap(line, width=width - hangindent)) + # To avoid corrupting multi-byte characters in line, we must wrap + # a Unicode string instead of a bytestring. + try: + u = line.decode(encoding.encoding) + w = padding.join(textwrap.wrap(u, width=width - hangindent)) + return w.encode(encoding.encoding) + except UnicodeDecodeError: + return padding.join(textwrap.wrap(line, width=width - hangindent)) def iterlines(iterator): for chunk in iterator: