[PATCH 0 of 1] debugcommands.py

Martin Geisler mg at aragost.com
Wed May 11 03:09:14 CDT 2011

Adrian Buehlmann <adrian at cadifra.com> writes:

> On 2011-05-10 22:28, Matt Mackall wrote:
>> One of the few things I would consider changing here is the commands
>> table. Ideally the command table entries would somehow be stored right
>> next to the command definition.
> Example:
> <snip>
> table = {}
> ...
> def init(ui, dest=".", **opts):
>     """create a new repository in the given directory
>     Initialize a new repository in the given directory. If the given
>     directory does not exist, it will be created.
>     If no directory is given, the current directory is used.
>     It is possible to specify an ``ssh://`` URL as the destination.
>     See :hg:`help urls` for more information.
>     Returns 0 on success.
>     """
>     hg.repository(hg.remoteui(ui, opts), ui.expandpath(dest), create=1)
> table["^init"] = (init,
>     remoteopts,
>     _('[-e CMD] [--remotecmd CMD] [DEST]'))
> </snip>
> would that be acceptable?

I think a decorator would be nicer:

           synopsis=_('[-e CMD] [--remotecmd CMD] [DEST]'))
  def init(ui, dest=".", **opts):

But as Benoit mentioned, this might impact the startup time negatively.
The decorator would have to do something like this:

  def command(name, options, synopsis):
      def decorator(func):
          table[name] = (func, options, synopsis)
          return func
      return decorator

which means that we get two extra function calls for every defined

Martin Geisler

aragost Trifork
Professional Mercurial support

More information about the Mercurial-devel mailing list