开发者

Modify behavior of core Mercurial commands using extensions?

Is it possible to modify the behavior of a core Mercurial command (e.g. hg commit or hg status) by creating an extension?

For example, would it be possible to modify hg commit to ask the user to enter an issue tracking ID?

I understand that hook scripts could be used, but such scripts are not distributed via hg pull and need to be configured 开发者_StackOverflowfor every repository used.


Answering my own question

The Mercurial API provides the extensions.wrapcommand(table, command, wrapper) method which seems to provide the desired feature.

From the source code:

Wrap the command named `command' in table.

Replace command in the command table with wrapper. The wrapped command will be inserted into the command table specified by the table argument. The wrapper will be called like wrapper(orig, *args, **kwargs) where orig is the original (wrapped) function, and *args, **kwargs are the arguments passed to it.

A couple examples:

  • The prompt extension by Steve Losh
  • The nobranch extension from Fog Creek


Just to note: both extensions and hooks have exactly the same mass-deployment limitations. In both cases you have to induce your internal users to download a piece of software, be it a hook or an extension, and then to enable it in either the hgrc in their homedir or within the repo.

For both hooks and extensions you can distribute the software using any mechanism and can enable them globally in /etc/mercurial/hgrc

Extensions have some advantages over hooks as to how deep they can dig in the mercurial internals, but deployment is identical.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜