Patchwork [v2] minirst: don't treat top level item as children of last item (issue4803)

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 2, 2015, 7:32 p.m.
Message ID <b0cc0e7b2ca2cee00975.1441222336@waste.org>
Download mbox | patch
Permalink /patch/10370/
State Accepted
Headers show

Comments

timeless@mozdev.org - Sept. 2, 2015, 7:32 p.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1441221128 14400
#      Wed Sep 02 15:12:08 2015 -0400
# Node ID b0cc0e7b2ca2cee0097500d999110a5a05a53a00
# Parent  f77a3f27cea533232dc107a72773e90e2de9549d
minirst: don't treat top level item as children of last item (issue4803)

test for "hg help -c config" in help config
Matt Mackall - Sept. 3, 2015, 10:59 p.m.
On Wed, 2015-09-02 at 14:32 -0500, timeless@mozdev.org wrote:
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1441221128 14400
> #      Wed Sep 02 15:12:08 2015 -0400
> # Node ID b0cc0e7b2ca2cee0097500d999110a5a05a53a00
> # Parent  f77a3f27cea533232dc107a72773e90e2de9549d
> minirst: don't treat top level item as children of last item (issue4803)

Queued for default, thanks.

Patch

diff --git a/mercurial/minirst.py b/mercurial/minirst.py
--- a/mercurial/minirst.py
+++ b/mercurial/minirst.py
@@ -727,6 +727,21 @@ 
             if not secs:
                 # add an initial empty section
                 secs = [('', 0, [])]
+            if b['type'] != 'margin':
+                pointer = 1
+                bindent = b['indent']
+                while pointer < len(secs):
+                    section = secs[-pointer][2][0]
+                    if section['type'] != 'margin':
+                        sindent = section['indent']
+                        if len(section['lines']) > 1:
+                            sindent += len(section['lines'][1]) - \
+                              len(section['lines'][1].lstrip(' '))
+                        if bindent >= sindent:
+                            break
+                    pointer += 1
+                if pointer > 1:
+                    secs.append(('', secs[-pointer][1] + 1, []))
             secs[-1][2].append(b)
     return secs
 
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -922,6 +922,22 @@ 
       "smtp.host"
           Host name of mail server, e.g. "mail.example.com".
   
+Help subsection:
+
+  $ hg help config.charsets |grep "Email example:" > /dev/null
+  [1]
+
+Last item in help config.*:
+
+  $ hg help config.`hg help config|grep '^    "'| \
+  >       tail -1|sed 's![ "]*!!g'`| \
+  >   grep "hg help -c config" > /dev/null
+  [1]
+
+note to use help -c for general hg help config:
+
+  $ hg help config |grep "hg help -c config" > /dev/null
+
 Test templating help
 
   $ hg help templating | egrep '(desc|diffstat|firstline|nonempty)  '