Patchwork help: only call doc() when it is callable

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 30, 2014, 6:09 p.m.
Message ID <1c91e84fa02a7c084cb3.1409422167@gps-mbp.local>
Download mbox | patch
Permalink /patch/5646/
State Accepted
Headers show

Comments

Gregory Szorc - Aug. 30, 2014, 6:09 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1409421984 -7200
#      Sat Aug 30 20:06:24 2014 +0200
# Node ID 1c91e84fa02a7c084cb3258c42d2989188163fb5
# Parent  188b8aa2120b03eead618ba150319074f4e3b42b
help: only call doc() when it is callable

`hg help -k` on my machine was aborting because the hg-prompt extension
was inserting a string and not a function into help.helptable and help
was blindly calling it.

This patch changes keyword searching to be more robust against
unexpected types.
Matt Mackall - Sept. 1, 2014, 9:22 p.m.
On Sat, 2014-08-30 at 20:09 +0200, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1409421984 -7200
> #      Sat Aug 30 20:06:24 2014 +0200
> # Node ID 1c91e84fa02a7c084cb3258c42d2989188163fb5
> # Parent  188b8aa2120b03eead618ba150319074f4e3b42b
> help: only call doc() when it is callable

Queued for stable, thanks. Please bear stable in mind when sending
patches, if only because it helps jump your patch to the front of my
priority queue.

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -86,11 +86,12 @@  def topicmatch(kw):
                'extensions': [],
                'extensioncommands': [],
                }
     for names, header, doc in helptable:
+        # Old extensions may use a str as doc.
         if (sum(map(lowercontains, names))
             or lowercontains(header)
-            or lowercontains(doc())):
+            or (callable(doc) and lowercontains(doc()))):
             results['topics'].append((names[0], header))
     import commands # avoid cycle
     for cmd, entry in commands.table.iteritems():
         if len(entry) == 3: