[PATCH 1 of 2] revset: don't suggest private or undocumented queries
Matt Harbison
mharbison72 at gmail.com
Sat Jun 20 16:29:53 UTC 2015
# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1434812396 14400
# Sat Jun 20 10:59:56 2015 -0400
# Node ID 49a621c1776823f568a42cbe0e223c6b4418a36a
# Parent 2748bf78a5bf610da4f2d90fd1eea19a3b360c04
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()'.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -5,7 +5,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
-import re
+import inspect, re, sys
import parser, util, error, hbisect, phases
import node
import heapq
@@ -391,7 +391,15 @@
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())
+
+ thismod = sys.modules[__name__]
+
+ def keep(obj):
+ return inspect.isfunction(obj) and obj.__doc__ is not None
+
+ public = [m[0] for m in inspect.getmembers(thismod, predicate=keep)]
+ syms = [s for s in symbols.keys() if s in public]
+ raise error.UnknownIdentifier(a[1], syms)
# functions
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -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'
More information about the Mercurial-devel
mailing list