[PATCH 4 of 4] minirst: filter blocks by full path to section
Yuya Nishihara
yuya at tcha.org
Wed Aug 29 09:43:36 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1533443644 -32400
# Sun Aug 05 13:34:04 2018 +0900
# Node ID 67e8a8521cb22163ad42ae99ee27960b8f539fc7
# Parent 1089fe141b360764d5a413ea87f382a22f898499
minirst: filter blocks by full path to section
diff --git a/mercurial/minirst.py b/mercurial/minirst.py
--- a/mercurial/minirst.py
+++ b/mercurial/minirst.py
@@ -678,7 +678,11 @@ def format(text, width=80, indent=0, kee
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 @@ def filtersections(blocks, section):
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 @@ def filtersections(blocks, section):
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 @@ def _getsections(blocks):
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 @@ def _getsections(blocks):
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
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1344,8 +1344,16 @@ Test repeated config section name
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 at example.com>". Environment variables in the username are
+ expanded.
+
+ (default: "$EMAIL" or "username at 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 @@ Test section name with dot
$ 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 @@ Show nested definitions
$ 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
More information about the Mercurial-devel
mailing list