changeset 25632:015c0d1087a3

revset: don't suggest private or undocumented queries I noticed when I mistyped 'matching', that it suggested '_matchfiles' as well. Rather than simply exclude names that start with '_', this excludes anything without a docstring. That way, if it isn't in the help text, it isn't suggested, such as 'wdir()'.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 20 Jun 2015 10:59:56 -0400
parents 2748bf78a5bf
children 0f44d35731d6
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Thu Jun 18 15:42:40 2015 -0500
+++ b/mercurial/revset.py	Sat Jun 20 10:59:56 2015 -0400
@@ -391,7 +391,11 @@
 def func(repo, subset, a, b):
     if a[0] == 'symbol' and a[1] in symbols:
         return symbols[a[1]](repo, subset, b)
-    raise error.UnknownIdentifier(a[1], symbols.keys())
+
+    keep = lambda fn: getattr(fn, '__doc__', None) is not None
+
+    syms = [s for (s, fn) in symbols.items() if keep(fn)]
+    raise error.UnknownIdentifier(a[1], syms)
 
 # functions
 
--- a/tests/test-revset.t	Thu Jun 18 15:42:40 2015 -0500
+++ b/tests/test-revset.t	Sat Jun 20 10:59:56 2015 -0400
@@ -1334,6 +1334,17 @@
   hg: parse error: unknown identifier: babar
   [255]
 
+Bogus function with a similar internal name doesn't suggest the internal name
+  $ log 'matches()'
+  hg: parse error: unknown identifier: matches
+  (did you mean 'matching'?)
+  [255]
+
+Undocumented functions aren't suggested as similar either
+  $ log 'wdir2()'
+  hg: parse error: unknown identifier: wdir2
+  [255]
+
 multiple revspecs
 
   $ hg log -r 'tip~1:tip' -r 'tip~2:tip~1' --template '{rev}\n'