What's the best way to execute a Mercurial command from an extension?

Paul Moore p.f.moore at gmail.com
Sun Apr 6 20:13:40 UTC 2008


I want to write an extension which basically pulls together a series
of Mercurial commands, and I'm not sure what the best way to do this
is.

It looks to me like the "canonical" interface for most commands is

    mercurial.commands.command_name(ui, repo, *other_args, **kw_args)

Is that a sensible way of calling an arbitrary command?

Also, I need to call the mq "strip" command. It appears that I can do this via

    from hgext.mq import strip
    strip(ui, repo, rev)

But what will happen if the mq extension is not present? A quick
experiment indicates that it will work whether or not mq is enabled
(in mercurial.ini) - is it OK to use it regardless? Furthermore, is it
possible for the import given to fail (and if so, should I check for
an exception and report the error if so)? Or am I worrying too much,
and because mq is distributed with Mercurial, it's OK to use it
regardless of whether the user enables the extension?

Thanks,
Paul.



More information about the Mercurial mailing list