help: rewrite parsing of help topic to not drop section name with dots
authorYuya Nishihara <yuya@tcha.org>
Sun, 05 Aug 2018 12:42:10 +0900
changeset 39339 d30867a745a1
parent 39338 fb9ee1ba5e42
child 39340 b2feccc199c2
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.
mercurial/help.py
tests/test-help.t
--- a/mercurial/help.py	Sun Aug 05 12:48:02 2018 +0900
+++ b/mercurial/help.py	Sun Aug 05 12:42:10 2018 +0900
@@ -642,8 +642,8 @@
 
     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 @@
         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:
--- a/tests/test-help.t	Sun Aug 05 12:48:02 2018 +0900
+++ b/tests/test-help.t	Sun Aug 05 12:42:10 2018 +0900
@@ -1344,52 +1344,14 @@
 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@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)
-  
+  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 @@
           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 '^$'