[PATCH 2 of 2] dispatch: provide help for disabled extensions and commands

Martin Geisler mg at lazybytes.net
Mon Dec 7 14:23:34 CST 2009


Brodie Rao <dackze at gmail.com> writes:

> # HG changeset patch
> # User Brodie Rao <me+hg at dackz.net>
> # Date 1260082485 18000
> # Node ID 77ebf6a52e3722b8dbe9f7a466c344c39cf7418d
> # Parent  29df34f954641a1e0b348cb8484bc8bb67d7aba3
> dispatch: provide help for disabled extensions and commands

> Before a command is declared unknown, the cmdtable of each extension in
> hgext is searched, starting with hgext.<cmdname>, and then every other
> extension. If there's a match, a help message suggesting the appropriate
> extension and how to enable them is printed.
>
> Every extension could potentially be imported, but for cases like rebase,
> relink, etc. only one extension is imported.

Clever :-)


It looks to me like you're both implementing this nice new feature and
also refactoring the code at the same time. It would be easier to see
what is only moved and what is edited if you did the refactoring first.

> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1579,10 +1579,14 @@ def help_(ui, name=None, with_version=Fa
>      def helpext(name):
>          try:
>              mod = extensions.find(name)
> +            doc = mod.__doc__
>          except KeyError:
> -            raise error.UnknownCommand(name)
> -
> -        doc = gettext(mod.__doc__) or _('no help text available')
> +            mod = None
> +            doc = extensions.disabledext(name)
> +            if not doc:
> +                raise error.UnknownCommand(name)
> +
> +        doc = gettext(doc) or _('no help text available')

This breaks when gettext() is given an already translated string.

> diff --git a/mercurial/extensions.py b/mercurial/extensions.py
> --- a/mercurial/extensions.py
> +++ b/mercurial/extensions.py
> @@ -6,7 +6,7 @@
>  # GNU General Public License version 2, incorporated herein by reference.
>  
>  import imp, os
> -import util, cmdutil, help
> +import util, cmdutil, help, error
>  from i18n import _, gettext
>  
>  _extensions = {}
> @@ -131,52 +131,110 @@ def wrapfunction(container, funcname, wr
>      setattr(container, funcname, wrap)
>      return origfn
>  
> +def _disabledpaths(init=True):
> +    import hgext
> +    extpath = os.path.dirname(os.path.abspath(hgext.__file__))
> +    try: # might not be a filesystem path
> +        files = os.listdir(extpath)
> +    except OSError:
> +        return {}
> +
> +    exts = {}
> +    for e in files:
> +        path = os.path.join(extpath, e)
> +        if e.endswith('.py'):
> +            name = e.rsplit('.', 1)[0]
> +        else:
> +            name = e
> +            modpath = os.path.join(extpath, e, '__init__.py')
> +            if not os.path.exists(modpath):
> +                continue
> +            elif init:
> +                path = modpath

I'm not sure what the 'init' argument means... I can of course see it's
being used here, but what does it do?

> +        if name in exts or name in _order or name == '__init__':
> +            continue
> +        exts[name] = path
> +    return exts

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20091207/e142c216/attachment.pgp>


More information about the Mercurial-devel mailing list