Patchwork help: distinguish sections when multiple match (issue4802)

login
register
mail settings
Submitter timeless@mozdev.org
Date Aug. 31, 2015, 1:11 a.m.
Message ID <48bdff8d80d3e1fd12d0.1440983488@waste.org>
Download mbox | patch
Permalink /patch/10331/
State Accepted
Headers show

Comments

timeless@mozdev.org - Aug. 31, 2015, 1:11 a.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1440975818 14400
#      Sun Aug 30 19:03:38 2015 -0400
# Node ID 48bdff8d80d3e1fd12d0852c77cdbf718f5094cb
# Parent  ab66c1dee405aca0c51b8f76eab255d805c194d7
help: distinguish sections when multiple match (issue4802)
Matt Mackall - Aug. 31, 2015, 10:36 p.m.
On Sun, 2015-08-30 at 20:11 -0500, timeless@mozdev.org wrote:
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1440975818 14400
> #      Sun Aug 30 19:03:38 2015 -0400
> # Node ID 48bdff8d80d3e1fd12d0852c77cdbf718f5094cb
> # Parent  ab66c1dee405aca0c51b8f76eab255d805c194d7
> help: distinguish sections when multiple match (issue4802)

Queued for default, thanks.

Patch

diff --git a/mercurial/minirst.py b/mercurial/minirst.py
--- a/mercurial/minirst.py
+++ b/mercurial/minirst.py
@@ -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,13 @@ 
     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
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -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)  '