1、
Handling repository events with hooks
可以通过Mercurial版本管理工具提供的hooks机制来处理repo的各种事件,从而实现对Mercurial的扩展,实现我们的特定需求。2、
常用的hooks event事件:摘自:http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html#sec:hook:precommitchangegroup: This is run after a group of changesets has been brought into the repository from elsewhere. 5 commentscommit: This is run after a new changeset has been created in the local repository. No commentsincoming: This is run once for each new changeset that is brought into the repository from elsewhere. Notice the difference from changegroup, which is run once per group of changesets brought in. No commentsoutgoing: This is run after a group of changesets has been transmitted from this repository. No commentsprechangegroup: This is run before starting to bring a group of changesets into the repository. 2 commentsprecommit: Controlling. This is run before starting a commit. 2 commentspreoutgoing: Controlling. This is run before starting to transmit a group of changesets from this repository. No commentspretag: Controlling. This is run before creating a tag. No commentspretxnchangegroup: Controlling. This is run after a group of changesets has been brought into the local repository from another, but before the transaction completes that will make the changes permanent in the repository. No commentspretxncommit: Controlling. This is run after a new changeset has been created in the local repository, but before the transaction completes that will make it permanent. One commentpreupdate: Controlling. This is run before starting an update or merge of the working directory. One commenttag: This is run after a tag is created. No commentsupdate: This is run after an update or merge of the working directory has finished. No comments
3、
hook配置:可以修改本地仓库下面.hg/hgrc配置文件,语法规则:The syntax for Python hooks is as follows:
hookname = python:modulename.submodule.callable
hookname = python:/path/to/python/module.py:callable例: [hooks] precommit = python:.hg/signoff.py:sign_commit_message4、函数参数:all hooks will take ui, repo,hooktype -- that's a very common pattern in Mercurial code (core, extensions, hooks, whatever)例:我们一般可以这样定义函数:import redef precommit_badbranch(ui, repo, **kwargs):branch = repo[None].branch()branch_re = re.compile(r'\d+\.\d+-branch$')if not branch_re.match(branch):ui.warn('invalid branch name %r (use. -branch)\n')return Truereturn False
5、返回值:
Hooks can be implemented as either external programs, or internal python calls. The meaning of the return value in both cases is based on the convention for external executables; in other words, a value of 0 means "success". For hooks implemented in python this can be a bit misleading, since it means you return "False" to indicate success and "True" (or throw an exception) to indicate failure. return True 表明失败, 则此命令执行会失败return False表明成功,此命令可以执行6、
The Mercurial API在写hook的时候,我们可以使用很多Mercurial提供的api,具体参见:https://www.mercurial-scm.org/wiki/MercurialApi参考:
http://hgbook.red-bean.com/ --重要https://www.mercurial-scm.org/wiki/HookExampleshttps://www.mercurial-scm.org/wiki/MercurialApihttps://www.mercurial-scm.org/wiki/Hookhttps://selenic.com/hg/help/hgrc