minirst: filter blocks by full path to section
authorYuya Nishihara <yuya@tcha.org>
Sun, 05 Aug 2018 13:34:04 +0900
changeset 39341 ca2f4dabf51d
parent 39340 b2feccc199c2
child 39342 d52fa7ddd1ac
minirst: filter blocks by full path to section
mercurial/minirst.py
tests/test-help.t
--- a/mercurial/minirst.py	Sun Aug 05 13:34:58 2018 +0900
+++ b/mercurial/minirst.py	Sun Aug 05 13:34:04 2018 +0900
@@ -678,7 +678,11 @@
         return formatplain(blocks, width=width)
 
 def filtersections(blocks, section):
-    """Select parsed blocks under the specified section"""
+    """Select parsed blocks under the specified section
+
+    The section name is separated by a dot, and matches the suffix of the
+    full section path.
+    """
     parents = []
     sections = _getsections(blocks)
     blocks = []
@@ -687,10 +691,10 @@
     synthetic = []
     collapse = True
     while i < len(sections):
-        name, nest, b = sections[i]
+        path, nest, b = sections[i]
         del parents[nest:]
         parents.append(i)
-        if name == section:
+        if path == section or path.endswith('.' + section):
             if lastparents != parents:
                 llen = len(lastparents)
                 plen = len(parents)
@@ -729,8 +733,9 @@
     return blocks
 
 def _getsections(blocks):
-    '''return a list of (section name, nesting level, blocks) tuples'''
+    '''return a list of (section path, nesting level, blocks) tuples'''
     nest = ""
+    names = ()
     level = 0
     secs = []
 
@@ -751,7 +756,8 @@
                 nest += i
             level = nest.index(i) + 1
             nest = nest[:level]
-            secs.append((getname(b), level, [b]))
+            names = names[:level] + (getname(b),)
+            secs.append(('.'.join(names), level, [b]))
         elif b['type'] in ('definition', 'field'):
             i = ' '
             if i not in nest:
@@ -772,7 +778,8 @@
                     elif siblingindent == indent:
                         level = sec[1]
                         break
-            secs.append((getname(b), level, [b]))
+            names = names[:level] + (getname(b),)
+            secs.append(('.'.join(names), level, [b]))
         else:
             if not secs:
                 # add an initial empty section
--- a/tests/test-help.t	Sun Aug 05 13:34:58 2018 +0900
+++ b/tests/test-help.t	Sun Aug 05 13:34:04 2018 +0900
@@ -1344,8 +1344,16 @@
 Test section name with dot
 
   $ hg help config.ui.username
-  abort: help section not found: config.ui.username
-  [255]
+      "ui.username"
+          The committer of a changeset created when running "commit". Typically
+          a person's name and email address, e.g. "Fred Widget
+          <fred@example.com>". Environment variables in the username are
+          expanded.
+  
+          (default: "$EMAIL" or "username@hostname". If the username in hgrc is
+          empty, e.g. if the system admin set "username =" in the system hgrc,
+          it has to be specified manually or in a different hgrc file)
+  
 
   $ hg help config.annotate.git
   abort: help section not found: config.annotate.git
@@ -1365,7 +1373,20 @@
   
 
   $ hg help config.commands.update.check
-  abort: help section not found: config.commands.update.check
+      "commands.update.check"
+          Determines what level of checking 'hg update' will perform before
+          moving to a destination revision. Valid values are "abort", "none",
+          "linear", and "noconflict". "abort" always fails if the working
+          directory has uncommitted changes. "none" performs no checking, and
+          may result in a merge with uncommitted changes. "linear" allows any
+          update as long as it follows a straight line in the revision history,
+          and may trigger a merge with uncommitted changes. "noconflict" will
+          allow any update which would not trigger a merge with uncommitted
+          changes, if any are present. (default: "linear")
+  
+
+  $ hg help config.ommands.update.check
+  abort: help section not found: config.ommands.update.check
   [255]
 
 Unrelated trailing paragraphs shouldn't be included
@@ -1388,6 +1409,14 @@
   $ hg help config.type | egrep '^$'|wc -l
   \s*3 (re)
 
+  $ hg help config.profiling.type.ls
+          "profiling.type.ls"
+            Use Python's built-in instrumenting profiler. This profiler works on
+            all platforms, but each line number it reports is the first line of
+            a function. This restriction makes it difficult to identify the
+            expensive parts of a non-trivial function.
+  
+
 Separate sections from subsections
 
   $ hg help config.format | egrep '^    ("|-)|^\s*$' | uniq