changeset 26113:9b70eda7529c

help: distinguish sections when multiple match (issue4802)
author timeless@mozdev.org
date Sun, 30 Aug 2015 19:03:38 -0400
parents cb6cfbf21735
children 9d6d3fee0c3f
files mercurial/minirst.py tests/test-help.t
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/minirst.py	Mon Aug 31 17:21:38 2015 -0500
+++ b/mercurial/minirst.py	Sun Aug 30 19:03:38 2015 -0400
@@ -656,13 +656,17 @@
 def format(text, width=80, indent=0, keep=None, style='plain', section=None):
     """Parse and format the text according to width."""
     blocks, pruned = parse(text, indent, keep or [])
+    parents = []
     if section:
         sections = getsections(blocks)
         blocks = []
         i = 0
         while i < len(sections):
             name, nest, b = sections[i]
+            del parents[nest:]
+            parents.append(name)
             if name == section:
+                b[0]['path'] = parents[3:]
                 blocks.extend(b)
 
                 ## Also show all subnested sections
@@ -674,6 +678,14 @@
     if style == 'html':
         text = formathtml(blocks)
     else:
+        if len([b for b in blocks if b['type'] == 'definition']) > 1:
+            i = 0
+            while i < len(blocks):
+                if blocks[i]['type'] == 'definition':
+                    if 'path' in blocks[i]:
+                        blocks[i]['lines'][0] = '"%s"' % '.'.join(
+                            blocks[i]['path'])
+                i += 1
         text = ''.join(formatblock(b, width) for b in blocks)
     if keep is None:
         return text
--- a/tests/test-help.t	Mon Aug 31 17:21:38 2015 -0500
+++ b/tests/test-help.t	Sun Aug 30 19:03:38 2015 -0400
@@ -912,6 +912,16 @@
       working directory is checked out, it is equivalent to null. If an
       uncommitted merge is in progress, "." is the revision of the first parent.
 
+Test repeated config section name
+
+  $ hg help config.host
+      "http_proxy.host"
+          Host name and (optional) port of the proxy server, for example
+          "myproxy:8000".
+  
+      "smtp.host"
+          Host name of mail server, e.g. "mail.example.com".
+  
 Test templating help
 
   $ hg help templating | egrep '(desc|diffstat|firstline|nonempty)  '