使用扩展修改核心 Mercurial 命令的行为?
是否可以通过创建扩展来修改核心 Mercurial 命令的行为(例如 hg commit
或 hg status
)?
例如,是否可以修改 hg commit
以要求用户输入问题跟踪 ID?
我知道可以使用挂钩脚本,但此类脚本不是通过 hg pull 分发的,并且需要为使用的每个存储库进行配置。
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 for every repository used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答我自己的问题
Mercurial API 提供了
extensions.wrapcommand(table, command,wrapper)
方法似乎提供了所需的功能。从源代码来看:
几个例子:
提示
Steve Losh 的扩展nobranch
从 Fog Creek 延伸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:
A couple examples:
prompt
extension by Steve Loshnobranch
extension from Fog Creek请注意:扩展和挂钩都具有完全相同的大规模部署限制。在这两种情况下,您都必须引导内部用户下载一个软件,无论是挂钩还是扩展,然后在其 homedir 的 hgrc 或存储库中启用它。
对于钩子和扩展,您可以使用任何机制分发软件,并可以在 /etc/mercurial/hgrc 中全局启用它们。
扩展比钩子有一些优势,因为它们可以深入 Mercurial 内部,但部署是相同的。
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.