# HG changeset patch # User timeless@mozdev.org # Date 2015-08-30 23:03:38 # Node ID 9b70eda7529c799150fc3c1a05e06978287ee8da # Parent cb6cfbf217358d9ee262824f5530aaedf42985ae help: distinguish sections when multiple match (issue4802) diff --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -656,13 +656,17 @@ def formatblocks(blocks, width): 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 @@ def format(text, width=80, indent=0, kee 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 @@ Test a help topic 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) '