[PATCH 1 of 2] revset: don't suggest private or undocumented queries

Matt Harbison mharbison72 at gmail.com
Sat Jun 20 12:18:32 CDT 2015


On Sat, 20 Jun 2015 12:51:04 -0400, Anton Shestakov <engored at ya.ru> wrote:

> 21.06.2015, 00:31, "Matt Harbison" <mharbison72 at gmail.com>:
>>  # 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)
>
> I wonder if it's possible to replace this with something like:
>
> syms = [s for (s, fn) in symbols.items() if getattr(fn, '__doc__', None)  
> is not None]
>
> and save on import inspect, sys? (I didn't try this)

Nice!  It works, so I'll send a v2.


More information about the Mercurial-devel mailing list