diff --git a/hgext/releasenotes.py b/hgext/releasenotes.py --- a/hgext/releasenotes.py +++ b/hgext/releasenotes.py @@ -16,7 +16,6 @@ from __future__ import absolute_import import difflib import errno import re -import textwrap from mercurial.i18n import _ from mercurial import ( @@ -29,6 +28,9 @@ from mercurial import ( scmutil, util, ) +from mercurial.utils import ( + stringutil, +) cmdtable = {} command = registrar.command(cmdtable) @@ -58,20 +60,6 @@ RE_ISSUE = br'\bissue ?[0-9]{4,6}(?![0-9 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 @@ def serializenotes(sections, notes): 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 @@ def serializenotes(sections, notes): 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('')