Mercurial hook:在最终推送之前在“服务器”上检查更改集作为补丁文件

时间:2013-10-28 16:43:38

标签: python mercurial mercurial-hook

简单场景: 我想在推送之前访问一次更改集,并将文件差异信息(以通常的git diff格式..或任何其他base64-serialisable格式)发送到我自己的RESTful Web服务以进行检查。我已经有一个pretxnchangegroup钩子设置.. 我可以访问节点,但hg export没有显示任何新内容(因为它们可能隐藏在此处描述:How do I reject pushes to a Mercurial server based on a script, without risking a bad pull during that time?),所以我想我必须通过Mercurial API。

问题:我没有“得到”如何从钩子中的Mercurial API以某种文本差异格式(git diff,无论......)轻松访问文件更改信息,似乎没有任何内容API文档:https://www.mercurial-scm.org/wiki/MercurialApi

仅仅是我还是这种“潜入Mercurial代码库”No Man's Land?我想避免挖掘这么深,但如果有必要,我会的。

1 个答案:

答案 0 :(得分:1)

您需要导入模块patch。它有一个方法diff(repo, prev, node, opts=opts),可以为您提供一个块列表。

查找文件cmdutil.py以获取如何使用该函数的示例;此文件包含hg export的代码(搜索def export)。

相关问题