[PATCH 2 of 4] help: rewrite parsing of help topic to not drop section name with dots
Yuya Nishihara
yuya at tcha.org
Wed Aug 29 09:43:34 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1533440530 -32400
# Sun Aug 05 12:42:10 2018 +0900
# Node ID 656e548c9349e1e98e166a67a7a6193e237ca613
# Parent a43d85dc663259467d20033cd6961d6d3c20bf4d
help: rewrite parsing of help topic to not drop section name with dots
A subtopic is no longer lowercased since it should be considered a part of
a topic path, not a section filter.
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -642,8 +642,8 @@ def help_(ui, commands, name, unknowncmd
return ''.join(rst)
-def formattedhelp(ui, commands, name, keep=None, unknowncmd=False, full=True,
- **opts):
+def formattedhelp(ui, commands, fullname, keep=None, unknowncmd=False,
+ full=True, **opts):
"""get help for a given topic (as a dotted name) as rendered rst
Either returns the rendered help text or raises an exception.
@@ -652,19 +652,17 @@ def formattedhelp(ui, commands, name, ke
keep = []
else:
keep = list(keep) # make a copy so we can mutate this later
- fullname = name
- section = None
- subtopic = None
- if name and '.' in name:
- name, remaining = name.split('.', 1)
- remaining = encoding.lower(remaining)
- if '.' in remaining:
- subtopic, section = remaining.split('.', 1)
- else:
- if name in subtopics:
- subtopic = remaining
- else:
- section = remaining
+
+ # <fullname> := <name>[.<subtopic][.<section>]
+ name = subtopic = section = None
+ if fullname is not None:
+ nameparts = fullname.split('.')
+ name = nameparts.pop(0)
+ if nameparts and name in subtopics:
+ subtopic = nameparts.pop(0)
+ if nameparts:
+ section = encoding.lower('.'.join(nameparts))
+
textwidth = ui.configint('ui', 'textwidth')
termwidth = ui.termwidth() - 2
if textwidth <= 0 or termwidth < textwidth:
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1344,52 +1344,14 @@ Test repeated config section name
Test section name with dot
$ hg help config.ui.username
- "auth.username"
- Optional. Username to authenticate with. If not given, and the remote
- site requires basic or digest authentication, the user will be
- prompted for it. Environment variables are expanded in the username
- letting you do "foo.username = $USER". If the URI includes a username,
- only "[auth]" entries with a matching username or without a username
- will be considered.
-
- "smtp.username"
- Optional. User name for authenticating with the SMTP server. (default:
- None)
-
- "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)
-
+ abort: help section not found: config.ui.username
+ [255]
$ hg help config.annotate.git
- "diff.git"
- Use git extended diff format.
-
+ abort: help section not found: config.annotate.git
+ [255]
$ hg help config.update.check
- "merge-tools.check"
- A list of merge success-checking options:
-
- "changed"
- Ask whether merge was successful when the merged file shows no
- changes.
-
- "conflicts"
- Check whether there are conflicts even though the tool reported
- success.
-
- "prompt"
- Always prompt for merge success, regardless of success reported by
- tool.
-
-
- $ hg help 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",
@@ -1402,6 +1364,10 @@ Test section name with dot
changes, if any are present. (default: "linear")
+ $ hg help config.commands.update.check
+ abort: help section not found: config.commands.update.check
+ [255]
+
Unrelated trailing paragraphs shouldn't be included
$ hg help config.extramsg | grep '^$'
More information about the Mercurial-devel
mailing list