What's the best way to execute a Mercurial command from an extension?
Steve Borho
steve at borho.org
Sun Apr 6 15:45:57 CDT 2008
On Sun, 2008-04-06 at 21:28 +0100, Paul Moore wrote:
> On 06/04/2008, Paul Moore <p.f.moore at gmail.com> wrote:
> > 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?
>
> Following on from this,
>
> 1) Is there a way of capturing (suppressing, probably) the command
> output, and checking for errors in the command?
> 2) Is there a way of knowing which arguments are required (e.g., date
> in commands.revert), other than by trial and error?
TortoiseHg has to deal with this quite a bit. We have two functions
that wrap generic mercurial commands, one for interactive commands that
may require user interaction (think http auth) and another more
efficient version for non-interactive commands. Both (HgThread, and
hgcmd_toq) are in this file.
http://hg.borho.org/tortoisehg-dev/file/66670a45162d/hggtk/hglib.py
Some of this might be a bit easier with some recent ui changes, but
TortoiseHg tries to be compatible with at least 0.9.4. In general, you
should probably read through dispatch.py from the mercurial source to
understand how command lines are processed.
--
Steve Borho (steve at borho.org)
http://www.borho.org/~steve/steve.asc
Key fingerprint = 2D08 E7CF B624 624C DE1F E2E4 B0C2 5292 F2C6 2C8C
More information about the Mercurial
mailing list