minirst: don't treat top level item as children of last item (issue4803)
authortimeless@mozdev.org
Wed, 02 Sep 2015 15:12:08 -0400
changeset 26157 65e41f388970
parent 26156 a112fffdb632
child 26158 342ab95a1f4b
minirst: don't treat top level item as children of last item (issue4803) test for "hg help -c config" in help config
mercurial/minirst.py
tests/test-help.t
--- a/mercurial/minirst.py	Wed Sep 02 22:05:58 2015 -0700
+++ b/mercurial/minirst.py	Wed Sep 02 15:12:08 2015 -0400
@@ -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
 
--- a/tests/test-help.t	Wed Sep 02 22:05:58 2015 -0700
+++ b/tests/test-help.t	Wed Sep 02 15:12:08 2015 -0400
@@ -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)  '