mercurial/util.py
changeset 9482 ca3390c19f88
parent 9417 4c3fb45123e5
parent 9480 44758742ad2e
child 9508 e2fd9b62349b
equal deleted inserted replaced
9481:829f5c2a2c2e 9482:ca3390c19f88
    12 This contains helper routines that are independent of the SCM core and
    12 This contains helper routines that are independent of the SCM core and
    13 hide platform-specific details from the core.
    13 hide platform-specific details from the core.
    14 """
    14 """
    15 
    15 
    16 from i18n import _
    16 from i18n import _
    17 import error, osutil
    17 import error, osutil, encoding
    18 import cStringIO, errno, re, shutil, sys, tempfile, traceback
    18 import cStringIO, errno, re, shutil, sys, tempfile, traceback
    19 import os, stat, time, calendar, random, textwrap
    19 import os, stat, time, calendar, random, textwrap
    20 import imp
    20 import imp
    21 
    21 
    22 # Python compatibility
    22 # Python compatibility
  1276         width = termwidth() - 2
  1276         width = termwidth() - 2
  1277     if width <= hangindent:
  1277     if width <= hangindent:
  1278         # adjust for weird terminal size
  1278         # adjust for weird terminal size
  1279         width = max(78, hangindent + 1)
  1279         width = max(78, hangindent + 1)
  1280     padding = '\n' + ' ' * hangindent
  1280     padding = '\n' + ' ' * hangindent
  1281     return padding.join(textwrap.wrap(line, width=width - hangindent))
  1281     # To avoid corrupting multi-byte characters in line, we must wrap
       
  1282     # a Unicode string instead of a bytestring.
       
  1283     u = line.decode(encoding.encoding)
       
  1284     w = padding.join(textwrap.wrap(u, width=width - hangindent))
       
  1285     return w.encode(encoding.encoding)
  1282 
  1286 
  1283 def iterlines(iterator):
  1287 def iterlines(iterator):
  1284     for chunk in iterator:
  1288     for chunk in iterator:
  1285         for line in chunk.splitlines():
  1289         for line in chunk.splitlines():
  1286             yield line
  1290             yield line