Patchwork D8639: py3: fix broken man page generation, it was generating `(default: NUL*)`

login
register
mail settings
Submitter phabricator
Date June 18, 2020, 12:15 a.m.
Message ID <differential-rev-PHID-DREV-dgklednlshho4ba3d2ua-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46526/
State Superseded
Headers show

Comments

phabricator - June 18, 2020, 12:15 a.m.
spectral created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `bytes(default)` was producing things like `(default: \x00)` when handed
  non-bytes values such as `1`, `10`, or `True`. The man page generation would
  apparently ignore these bytes and produce man pages that had the string
  `(default: )`.

TEST PLAN
  - Ran `cd doc; python3 gendoc.py "hg.1.gendoc"` and grepped for bad output
  - Ran `make deb`, extracted the deb, manually inspected `hg.1` file.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D8639

AFFECTED FILES
  doc/gendoc.py

CHANGE DETAILS




To: spectral, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -85,7 +85,12 @@ 
         if b'\n' in desc:
             # only remove line breaks and indentation
             desc = b' '.join(l.lstrip() for l in desc.split(b'\n'))
-        desc += default and _(b" (default: %s)") % bytes(default) or b""
+        if default:
+            defaulttmpl = _(b" (default: %s)")
+            if defaulttmpl:
+                if not isinstance(default, bytes):
+                    default = repr(default).encode('latin1')
+                desc += defaulttmpl % default
         yield (b", ".join(allopts), desc)