##// END OF EJS Templates
releasenotes: use stringutil.wrap() instead of handcrafted TextWrapper wrapper...
Yuya Nishihara -
r40279:96e50dfd default
parent child Browse files
Show More
@@ -16,7 +16,6 from __future__ import absolute_import
16 import difflib
16 import difflib
17 import errno
17 import errno
18 import re
18 import re
19 import textwrap
20
19
21 from mercurial.i18n import _
20 from mercurial.i18n import _
22 from mercurial import (
21 from mercurial import (
@@ -29,6 +28,9 from mercurial import (
29 scmutil,
28 scmutil,
30 util,
29 util,
31 )
30 )
31 from mercurial.utils import (
32 stringutil,
33 )
32
34
33 cmdtable = {}
35 cmdtable = {}
34 command = registrar.command(cmdtable)
36 command = registrar.command(cmdtable)
@@ -58,20 +60,6 RE_ISSUE = br'\bissue ?[0-9]{4,6}(?![0-9
58
60
59 BULLET_SECTION = _('Other Changes')
61 BULLET_SECTION = _('Other Changes')
60
62
61 if pycompat.ispy3:
62 class byteswrapper(object):
63 def __init__(self, **kwargs):
64 for k in kwargs:
65 v = kwargs[k]
66 if not isinstance(v, str) and isinstance(v, bytes):
67 kwargs[k] = v.decode('utf8')
68 self._tw = textwrap.TextWrapper(**kwargs)
69 def wrap(self, data):
70 return [
71 l.encode('utf8') for l in self._tw.wrap(data.decode('utf8'))]
72 else:
73 byteswrapper = textwrap.TextWrapper
74
75 class parsedreleasenotes(object):
63 class parsedreleasenotes(object):
76 def __init__(self):
64 def __init__(self):
77 self.sections = {}
65 self.sections = {}
@@ -457,11 +445,11 def serializenotes(sections, notes):
457 lines.append('-' * len(title))
445 lines.append('-' * len(title))
458 lines.append('')
446 lines.append('')
459
447
460 wrapper = byteswrapper(width=78)
461 for i, para in enumerate(paragraphs):
448 for i, para in enumerate(paragraphs):
462 if i:
449 if i:
463 lines.append('')
450 lines.append('')
464 lines.extend(wrapper.wrap(' '.join(para)))
451 lines.extend(stringutil.wrap(' '.join(para),
452 width=78).splitlines())
465
453
466 lines.append('')
454 lines.append('')
467
455
@@ -479,17 +467,17 def serializenotes(sections, notes):
479 lines.append('')
467 lines.append('')
480
468
481 for paragraphs in nontitled:
469 for paragraphs in nontitled:
482 wrapper = byteswrapper(initial_indent='* ',
470 lines.extend(stringutil.wrap(' '.join(paragraphs[0]),
483 subsequent_indent=' ',
471 width=78,
484 width=78)
472 initindent='* ',
485 lines.extend(wrapper.wrap(' '.join(paragraphs[0])))
473 hangindent=' ').splitlines())
486
474
487 wrapper = byteswrapper(initial_indent=' ',
488 subsequent_indent=' ',
489 width=78)
490 for para in paragraphs[1:]:
475 for para in paragraphs[1:]:
491 lines.append('')
476 lines.append('')
492 lines.extend(wrapper.wrap(' '.join(para)))
477 lines.extend(stringutil.wrap(' '.join(para),
478 width=78,
479 initindent=' ',
480 hangindent=' ').splitlines())
493
481
494 lines.append('')
482 lines.append('')
495
483
General Comments 0
You need to be logged in to leave comments. Login now