##// END OF EJS Templates
util: fix ellipsis() not to break multi-byte sequence (issue2564)...
Yuya Nishihara -
r13225:e3bf1670 1.7.3 stable
parent child Browse files
Show More
@@ -1242,12 +1242,23 b' def email(author):'
1242 r = None
1242 r = None
1243 return author[author.find('<') + 1:r]
1243 return author[author.find('<') + 1:r]
1244
1244
1245 def _ellipsis(text, maxlength):
1246 if len(text) <= maxlength:
1247 return text, False
1248 else:
1249 return "%s..." % (text[:maxlength - 3]), True
1250
1245 def ellipsis(text, maxlength=400):
1251 def ellipsis(text, maxlength=400):
1246 """Trim string to at most maxlength (default: 400) characters."""
1252 """Trim string to at most maxlength (default: 400) characters."""
1247 if len(text) <= maxlength:
1253 try:
1254 # use unicode not to split at intermediate multi-byte sequence
1255 utext, truncated = _ellipsis(text.decode(encoding.encoding),
1256 maxlength)
1257 if not truncated:
1248 return text
1258 return text
1249 else:
1259 return utext.encode(encoding.encoding)
1250 return "%s..." % (text[:maxlength - 3])
1260 except (UnicodeDecodeError, UnicodeEncodeError):
1261 return _ellipsis(text, maxlength)[0]
1251
1262
1252 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False):
1263 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False):
1253 '''yield every hg repository under path, recursively.'''
1264 '''yield every hg repository under path, recursively.'''
@@ -302,3 +302,49 b' test merge'
302 changeset 22c88b85aa27 in b
302 changeset 22c88b85aa27 in b
303 description: merge
303 description: merge
304 (run 'hg update' to get a working copy)
304 (run 'hg update' to get a working copy)
305
306 truncate multi-byte subject
307
308 $ cat <<EOF >> $HGRCPATH
309 > [notify]
310 > maxsubject = 4
311 > EOF
312 $ echo a >> a/a
313 $ hg --cwd a --encoding utf-8 commit -A -d '0 0' \
314 > -m `python -c 'print "\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4"'`
315 $ hg --traceback --cwd b --encoding utf-8 pull ../a | \
316 > python -c 'import sys,re; print re.sub("\n\t", " ", sys.stdin.read()),'
317 pulling from ../a
318 searching for changes
319 adding changesets
320 adding manifests
321 adding file changes
322 added 1 changesets with 1 changes to 1 files
323 Content-Type: text/plain; charset="us-ascii"
324 MIME-Version: 1.0
325 Content-Transfer-Encoding: 8bit
326 X-Test: foo
327 Date: * (glob)
328 Subject: \xc3\xa0... (esc)
329 From: test@test.com
330 X-Hg-Notification: changeset 4a47f01c1356
331 Message-Id: <*> (glob)
332 To: baz@test.com, foo@bar
333
334 changeset 4a47f01c1356 in b
335 description: \xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4 (esc)
336 diffstat:
337
338 a | 1 +
339 1 files changed, 1 insertions(+), 0 deletions(-)
340
341 diffs (7 lines):
342
343 diff -r 22c88b85aa27 -r 4a47f01c1356 a
344 --- a/a Thu Jan 01 00:00:03 1970 +0000
345 +++ b/a Thu Jan 01 00:00:00 1970 +0000
346 @@ -1,2 +1,3 @@
347 a
348 a
349 +a
350 (run 'hg update' to get a working copy)
General Comments 0
You need to be logged in to leave comments. Login now