从 python hook 调用 Mercurial 命令(“hg update”)
我在 Windows 2008 64 位和 IIS 上设置了 Mercurial hgweb。存储库的位置是网络共享。
我想在存储库上创建一个挂钩,以在更改组上发出“hg update”命令。我无法使用外部挂钩,因为这会以网络共享作为工作目录启动 cmd.exe(并且 cmd.exe 不支持网络共享)。
因此,我正在寻找一个调用 Mercurial 命令的 python 钩子示例。我注意到有一个 Mercurial.commands 模块,但我在网上找不到任何示例,而且我对 Python 的经验也不是很多。
是否有任何使用 Python 挂钩调用 Mercurial 命令的示例 - 是否可以在 hgrc 中完成这一切,或者我是否需要外部 .py 文件?
I have Mercurial hgweb set up on Windows 2008 64 bit and IIS. The location of the repositories is a network share.
I want to create a hook on the repository to issue an "hg update" command on a changeroup. I cannot use the external hook as this would start cmd.exe with the network share as the working directory (and cmd.exe does not support network shares).
Therefore, I'm looking to find an example of a python hook that calls a mercurial command. I notice that there is a mercurial.commands module, but I cannot find any examples on the webs and I'm not very experienced with Python.
Are there any examples to call a mercurial command using a Python hook - and is it possible to do this all in the hgrc, or do I need an external .py file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要一个用于 Python 扩展的外部
.py
文件。要像从命令行调用 Mercurial 一样使用内部 API,请使用这是 Mercurial 1.9 之后的语法。在早期版本中,您将使用
传递给
request
或dispatch
的列表是命令行上hg
后面的参数。You need an external
.py
file for a Python extension. To use the internal API as if Mercurial was invoked from the command line, then useThis is the syntax after Mercurial 1.9. In earlier versions you would use
The list you pass to
request
ordispatch
is the arguments followinghg
on the command line.受到 Martin 回答的启发,我想我应该尝试编写一些 Python,以下是我如何让它工作的。我正在使用 Mercurial 2.0.2 和 Mercurial.commands 模块(据我所知,它包含在 Mercurial Python 包中)。
我在服务器上创建了一个 myhook.py 文件:
然后,在服务器上的 .hg/hgrc 文件中,我添加了以下内容:
我将更改执行命令的行以专门更新“提示”。如果您使用命名分支,那么如上面所示,该命令将不起作用。我相信这样会更好:
命令.update(ui, repo, repo['tip'])
Inspired by Martin's answer, I thought I would attempt to write some Python, and here is how I managed to get it working. I am using Mercurial 2.0.2 and the mercurial.commands module (which, AFAIK, is included in the Mercurial Python package).
I created a myhook.py file on the server:
Then, in my .hg/hgrc file on the server, I added the following:
I would change the line where the command is executed to specifically update to the 'tip'. If you use named branches then as it is above the command will have no effect. I believe this would be better:
commands.update(ui, repo, repo['tip'])