# HG changeset patch # User Yuya Nishihara # Date 1539426583 -7200 # Node ID 96e50dfd8c9425c277cb0aeeffa4f9488dfa9a00 # Parent 19ed212de2d102731daffee4185eb6a5295bb8f1 releasenotes: use stringutil.wrap() instead of handcrafted TextWrapper wrapper It's silly to splitlines() a joined string, but we don't care the performance here. diff -r 19ed212de2d1 -r 96e50dfd8c94 hgext/releasenotes.py --- a/hgext/releasenotes.py Sat Oct 13 00:22:05 2018 -0700 +++ b/hgext/releasenotes.py Sat Oct 13 12:29:43 2018 +0200 @@ -16,7 +16,6 @@ import difflib import errno import re -import textwrap from mercurial.i18n import _ from mercurial import ( @@ -29,6 +28,9 @@ scmutil, util, ) +from mercurial.utils import ( + stringutil, +) cmdtable = {} command = registrar.command(cmdtable) @@ -58,20 +60,6 @@ BULLET_SECTION = _('Other Changes') -if pycompat.ispy3: - class byteswrapper(object): - def __init__(self, **kwargs): - for k in kwargs: - v = kwargs[k] - if not isinstance(v, str) and isinstance(v, bytes): - kwargs[k] = v.decode('utf8') - self._tw = textwrap.TextWrapper(**kwargs) - def wrap(self, data): - return [ - l.encode('utf8') for l in self._tw.wrap(data.decode('utf8'))] -else: - byteswrapper = textwrap.TextWrapper - class parsedreleasenotes(object): def __init__(self): self.sections = {} @@ -457,11 +445,11 @@ lines.append('-' * len(title)) lines.append('') - wrapper = byteswrapper(width=78) for i, para in enumerate(paragraphs): if i: lines.append('') - lines.extend(wrapper.wrap(' '.join(para))) + lines.extend(stringutil.wrap(' '.join(para), + width=78).splitlines()) lines.append('') @@ -479,17 +467,17 @@ lines.append('') for paragraphs in nontitled: - wrapper = byteswrapper(initial_indent='* ', - subsequent_indent=' ', - width=78) - lines.extend(wrapper.wrap(' '.join(paragraphs[0]))) + lines.extend(stringutil.wrap(' '.join(paragraphs[0]), + width=78, + initindent='* ', + hangindent=' ').splitlines()) - wrapper = byteswrapper(initial_indent=' ', - subsequent_indent=' ', - width=78) for para in paragraphs[1:]: lines.append('') - lines.extend(wrapper.wrap(' '.join(para))) + lines.extend(stringutil.wrap(' '.join(para), + width=78, + initindent=' ', + hangindent=' ').splitlines()) lines.append('')